Commit 22bffd04 authored by Greg Messner's avatar Greg Messner
Browse files

Improved handling of exceptions.

parent b0bf7ed7
...@@ -147,9 +147,10 @@ public class SystemHookManager implements HookManager { ...@@ -147,9 +147,10 @@ public class SystemHookManager implements HookManager {
} }
// Unmarshal the tree to a concrete instance of a SystemHookEvent and fire the event to any listeners // Unmarshal the tree to a concrete instance of a SystemHookEvent and fire the event to any listeners
SystemHookEvent event;
try { try {
SystemHookEvent event = jacksonJson.unmarshal(SystemHookEvent.class, tree); event = jacksonJson.unmarshal(SystemHookEvent.class, tree);
if (LOGGER.isLoggable(Level.FINE)) { if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(event.getEventName() + "\n" + jacksonJson.marshal(event) + "\n"); LOGGER.fine(event.getEventName() + "\n" + jacksonJson.marshal(event) + "\n");
} }
...@@ -157,12 +158,21 @@ public class SystemHookManager implements HookManager { ...@@ -157,12 +158,21 @@ public class SystemHookManager implements HookManager {
StringBuffer requestUrl = request.getRequestURL(); StringBuffer requestUrl = request.getRequestURL();
event.setRequestUrl(requestUrl != null ? requestUrl.toString() : null); event.setRequestUrl(requestUrl != null ? requestUrl.toString() : null);
event.setRequestQueryString(request.getQueryString()); event.setRequestQueryString(request.getQueryString());
} catch (Exception e) {
LOGGER.warning(String.format("Error processing JSON data, exception=%s, error=%s",
e.getClass().getSimpleName(), e.getMessage()));
throw new GitLabApiException(e);
}
try {
fireEvent(event); fireEvent(event);
return (event); return (event);
} catch (Exception e) { } catch (Exception e) {
LOGGER.warning("Error processing JSON data, exception=" + LOGGER.warning(String.format("Error processing event, exception=%s, error=%s",
e.getClass().getSimpleName() + ", error=" + e.getMessage()); e.getClass().getSimpleName(), e.getMessage()));
throw new GitLabApiException(e); throw new GitLabApiException(e);
} }
} }
......
...@@ -116,9 +116,9 @@ public class WebHookManager implements HookManager { ...@@ -116,9 +116,9 @@ public class WebHookManager implements HookManager {
throw new GitLabApiException(message); throw new GitLabApiException(message);
} }
Event event;
try { try {
Event event;
if (LOGGER.isLoggable(Level.FINE)) { if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(HttpRequestUtils.getShortRequestDump(eventName + " webhook", true, request)); LOGGER.fine(HttpRequestUtils.getShortRequestDump(eventName + " webhook", true, request));
String postData = HttpRequestUtils.getPostDataAsString(request); String postData = HttpRequestUtils.getPostDataAsString(request);
...@@ -130,13 +130,22 @@ public class WebHookManager implements HookManager { ...@@ -130,13 +130,22 @@ public class WebHookManager implements HookManager {
event = jacksonJson.unmarshal(Event.class, reader); event = jacksonJson.unmarshal(Event.class, reader);
} }
} catch (Exception e) {
LOGGER.warning(String.format("Error processing JSON data, exception=%s, error=%s",
e.getClass().getSimpleName(), e.getMessage()));
throw new GitLabApiException(e);
}
try {
event.setRequestUrl(request.getRequestURL().toString()); event.setRequestUrl(request.getRequestURL().toString());
event.setRequestQueryString(request.getQueryString()); event.setRequestQueryString(request.getQueryString());
fireEvent(event); fireEvent(event);
return (event); return (event);
} catch (Exception e) { } catch (Exception e) {
LOGGER.warning("Error parsing JSON data, exception=" + e.getClass().getSimpleName() + ", error=" + e.getMessage()); LOGGER.warning(String.format("Error processing event, exception=%s, error=%s",
e.getClass().getSimpleName(), e.getMessage()));
throw new GitLabApiException(e); throw new GitLabApiException(e);
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment