From 7d10bd8bbc106b651ec66f6b2ecaaab6e0b1b35b Mon Sep 17 00:00:00 2001 From: Ivan Pesin Date: Fri, 15 Sep 2017 20:18:41 -0400 Subject: [PATCH] Catch error on command execution with include-command-output-in-response=false --- webhook.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/webhook.go b/webhook.go index d3dc48b..b57b4f9 100644 --- a/webhook.go +++ b/webhook.go @@ -277,18 +277,17 @@ func hookHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set(responseHeader.Name, responseHeader.Value) } - if matchedHook.CaptureCommandOutput { - response, err := handleHook(matchedHook, rid, &headers, &query, &payload, &body) + response, err := handleHook(matchedHook, rid, &headers, &query, &payload, &body) + if err != nil { + w.Header().Set("Content-Type", "text/plain; charset=utf-8") + w.WriteHeader(http.StatusInternalServerError) + fmt.Fprintf(w, "Error occurred while executing the hook's command. Please check your logs for more details.") + return + } - if err != nil { - w.Header().Set("Content-Type", "text/plain; charset=utf-8") - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, "Error occurred while executing the hook's command. Please check your logs for more details.") - } else { - fmt.Fprintf(w, response) - } + if matchedHook.CaptureCommandOutput { + fmt.Fprintf(w, response) } else { - go handleHook(matchedHook, rid, &headers, &query, &payload, &body) fmt.Fprintf(w, matchedHook.ResponseMessage) } return