@@ -21,7 +21,7 @@ import (
2121)
2222
2323const (
24- version = "2.4 .0"
24+ version = "2.5 .0"
2525)
2626
2727var (
@@ -222,8 +222,15 @@ func hookHandler(w http.ResponseWriter, r *http.Request) {
222222 }
223223
224224 if matchedHook .CaptureCommandOutput {
225- response := handleHook (matchedHook , & headers , & query , & payload , & body )
226- fmt .Fprintf (w , response )
225+ response , err := handleHook (matchedHook , & headers , & query , & payload , & body )
226+
227+ if err != nil {
228+ w .Header ().Set ("Content-Type" , "text/plain; charset=utf-8" )
229+ w .WriteHeader (http .StatusInternalServerError )
230+ fmt .Fprintf (w , "Error occurred while executing the hook's command. Please check your logs for more details." )
231+ } else {
232+ fmt .Fprintf (w , response )
233+ }
227234 } else {
228235 go handleHook (matchedHook , & headers , & query , & payload , & body )
229236 fmt .Fprintf (w , matchedHook .ResponseMessage )
@@ -241,7 +248,7 @@ func hookHandler(w http.ResponseWriter, r *http.Request) {
241248 }
242249}
243250
244- func handleHook (h * hook.Hook , headers , query , payload * map [string ]interface {}, body * []byte ) string {
251+ func handleHook (h * hook.Hook , headers , query , payload * map [string ]interface {}, body * []byte ) ( string , error ) {
245252 var err error
246253
247254 cmd := exec .Command (h .ExecuteCommand )
@@ -261,28 +268,17 @@ func handleHook(h *hook.Hook, headers, query, payload *map[string]interface{}, b
261268
262269 log .Printf ("executing %s (%s) with arguments %q and environment %s using %s as cwd\n " , h .ExecuteCommand , cmd .Path , cmd .Args , envs , cmd .Dir )
263270
264- out , err := cmd .CombinedOutput ()
271+ out , err := cmd .Output ()
265272
266273 log .Printf ("command output: %s\n " , out )
267274
268- var errorResponse string
269-
270275 if err != nil {
271276 log .Printf ("error occurred: %+v\n " , err )
272- errorResponse = fmt .Sprintf ("%+v" , err )
273277 }
274278
275279 log .Printf ("finished handling %s\n " , h .ID )
276280
277- var response []byte
278- response , err = json .Marshal (& hook.CommandStatusResponse {ResponseMessage : h .ResponseMessage , Output : string (out ), Error : errorResponse })
279-
280- if err != nil {
281- log .Printf ("error marshalling response: %+v" , err )
282- return h .ResponseMessage
283- }
284-
285- return string (response )
281+ return string (out ), err
286282}
287283
288284func reloadHooks () {
0 commit comments