Skip to content

Commit 320e88c

Browse files
tiaanlgmessner
authored andcommitted
Rework exception handling to attach original exception. (#125)
* Rework exception handling so that original exception is attached to GitlabApiException. * Simplify exception handling, but keeping relevant data. * Remove unused imports
1 parent 2a4affe commit 320e88c

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

src/main/java/org/gitlab4j/api/webhook/WebHookManager.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
package org.gitlab4j.api.webhook;
33

4-
import java.io.IOException;
54
import java.io.InputStreamReader;
65
import java.util.List;
76
import java.util.concurrent.CopyOnWriteArrayList;
@@ -15,9 +14,6 @@
1514
import org.gitlab4j.api.utils.HttpRequestUtils;
1615
import org.gitlab4j.api.utils.JacksonJson;
1716

18-
import com.fasterxml.jackson.core.JsonParseException;
19-
import com.fasterxml.jackson.databind.JsonMappingException;
20-
2117
/**
2218
* This class provides a handler for processing GitLab WebHook callouts.
2319
*/
@@ -81,7 +77,6 @@ public void handleEvent(HttpServletRequest request) throws GitLabApiException {
8177
throw new GitLabApiException(message);
8278
}
8379

84-
String errorMessage = null;
8580
try {
8681

8782
Event event;
@@ -98,22 +93,10 @@ public void handleEvent(HttpServletRequest request) throws GitLabApiException {
9893

9994
fireEvent(event);
10095

101-
} catch (JsonParseException jpe) {
102-
errorMessage = jpe.getMessage();
103-
LOG.warning("Error parsing JSON data, error=" + errorMessage);
104-
} catch (JsonMappingException jme) {
105-
errorMessage = jme.getMessage();
106-
LOG.warning("Error mapping JSON data, error=" + errorMessage);
107-
} catch (IOException ioe) {
108-
errorMessage = ioe.getMessage();
109-
LOG.warning("Error reading JSON data, error=" + errorMessage);
11096
} catch (Exception e) {
111-
errorMessage = e.getMessage();
112-
LOG.warning("Unexpected error reading JSON data, error=" + errorMessage);
97+
LOG.warning("Error parsing JSON data, exception=" + e.getClass().getSimpleName() + ", error=" + e.getMessage());
98+
throw new GitLabApiException(e);
11399
}
114-
115-
if (errorMessage != null)
116-
throw new GitLabApiException(errorMessage);
117100
}
118101

119102
/**

0 commit comments

Comments
 (0)