diff options
Diffstat (limited to 'vendor/github.com/nlopes/slack/misc.go')
-rw-r--r-- | vendor/github.com/nlopes/slack/misc.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/vendor/github.com/nlopes/slack/misc.go b/vendor/github.com/nlopes/slack/misc.go index c0f023cb..57f39104 100644 --- a/vendor/github.com/nlopes/slack/misc.go +++ b/vendor/github.com/nlopes/slack/misc.go @@ -9,6 +9,7 @@ import ( "io/ioutil" "mime/multipart" "net/http" + "net/http/httputil" "net/url" "os" "path/filepath" @@ -96,6 +97,13 @@ func postWithMultipartResponse(path string, filepath string, values url.Values, return err } defer resp.Body.Close() + + // Slack seems to send an HTML body along with 5xx error codes. Don't parse it. + if resp.StatusCode != 200 { + logResponse(resp, debug) + return fmt.Errorf("Slack server error: %s.", resp.Status) + } + return parseResponseBody(resp.Body, &intf, debug) } @@ -117,3 +125,16 @@ func parseAdminResponse(method string, teamName string, values url.Values, intf endpoint := fmt.Sprintf(SLACK_WEB_API_FORMAT, teamName, method, time.Now().Unix()) return postForm(endpoint, values, intf, debug) } + +func logResponse(resp *http.Response, debug bool) error { + if debug { + text, err := httputil.DumpResponse(resp, true) + if err != nil { + return err + } + + logger.Print(text) + } + + return nil +} |