Skip to content

Commit b883609

Browse files
arschlesAaron Schlesinger
authored andcommitted
fix(receive.go): return a concrete error type
1 parent 8b0e20e commit b883609

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

pkg/gitreceive/receive.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ import (
2323
// -d "{\"receive_user\": \"$username\", \"receive_repo\": \"$app\", \"sha\": \"$sha\", \"fingerprint\": \"$fingerprint\", \"ssh_connection\": \"$SSH_CONNECTION\", \"ssh_original_command\": \"$SSH_ORIGINAL_COMMAND\"}" \
2424
// --silent "http://$DEIS_WORKFLOW_SERVICE_HOST:$DEIS_WORKFLOW_SERVICE_PORT/v2/hooks/push" >/dev/null
2525

26+
type errInvalidHTTPStatusCode struct {
27+
expected int
28+
actual int
29+
}
30+
31+
func (e errInvalidHTTPStatusCode) Error() string {
32+
return fmt.Sprintf("expected status code %d, got %d", e.expected, e.actual)
33+
}
34+
2635
func receive(conf *Config, newRev string) error {
2736
urlStr := fmt.Sprintf("http://%s:%s/v2/hooks/push", conf.WorkflowHost, conf.WorkflowPort)
2837
bodyMap := map[string]string{
@@ -42,13 +51,13 @@ func receive(conf *Config, newRev string) error {
4251
return err
4352
}
4453

45-
// TODO: inspect resp for status code
4654
// TODO: use ctxhttp here (https://godoc.org/golang.org/x/net/context/ctxhttp)
47-
// resp, err := http.Do(req)
48-
_, err = http.DefaultClient.Do(req)
55+
resp, err = http.DefaultClient.Do(req)
4956
if err != nil {
5057
return err
5158
}
52-
// TODO: inspect resp for status code
59+
if resp.StatusCode != 201 {
60+
return errInvalidHTTPStatusCode{expected: 201, actual: resp.StatusCode}
61+
}
5362
return nil
5463
}

0 commit comments

Comments
 (0)