Skip to content

Commit

Permalink
fix(webhooks): handle NPE when source invalid (#552)
Browse files Browse the repository at this point in the history
handle an NPM when calling the webhook controller with an invalid
source.
  • Loading branch information
ethanfrogers committed May 17, 2019
1 parent 0bacac7 commit 1a1dc7c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ class WebhooksController {
}

if (type == 'git') {
GitWebhookHandler handler = scmWebhookHandler.getHandler(source)
GitWebhookHandler handler
try {
handler = scmWebhookHandler.getHandler(source)
} catch (Exception e) {
log.error("Unable to handle SCM source: {}", source)
throw e
}
handler.handle(event, postedEvent)
// shouldSendEvent should be called after the event
// has been processed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public ScmWebhookHandler(List<GitWebhookHandler> webhookEventHandlers) {
}

public GitWebhookHandler getHandler(String source) {
return webhookEventHandlers.stream().filter(h -> h.handles(source)).findFirst().orElse(null);
return webhookEventHandlers.stream()
.filter(h -> h.handles(source))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Invalid SCM handler source" + source));
}
}

0 comments on commit 1a1dc7c

Please sign in to comment.