Skip to content
This repository was archived by the owner on Oct 28, 2022. It is now read-only.

Commit 3108ce3

Browse files
committed
Also error on hook calls with response errors
1 parent c54ec42 commit 3108ce3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

models/onMatchHook.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package models
22

33
import (
44
"errors"
5+
"fmt"
56
"io"
7+
"io/ioutil"
68
"net/http"
79

810
"github.com/apex/log"
@@ -98,11 +100,19 @@ func (h *OnMatchHook) Call(body io.Reader, dataKind DataKind) (http.Header, erro
98100
}
99101
}
100102

101-
// We don't really care about what the response is
102-
_, err = http.DefaultClient.Do(req)
103+
resp, err := http.DefaultClient.Do(req)
103104
if err != nil {
104105
log.WithError(err).WithField("url", h.URL).WithField("id", h.ID.Hex()).Warnf("Failed calling hook")
105106
}
106107

108+
if resp.StatusCode >= 400 {
109+
respBody, err := ioutil.ReadAll(resp.Body)
110+
if err != nil {
111+
return req.Header, fmt.Errorf("hook returned status code \"%s\" with a unreadable message, error: %s", resp.Status, err.Error())
112+
}
113+
114+
return req.Header, fmt.Errorf("hook returned status code \"%s\" with message: %s", resp.Status, string(respBody))
115+
}
116+
107117
return req.Header, nil
108118
}

0 commit comments

Comments
 (0)