diff options
| author | Christine Dodrill <me@christine.website> | 2019-01-29 03:21:52 -0800 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2019-01-29 03:21:52 -0800 |
| commit | b395841f422fd9c6e50b4be979da0f308f9499a9 (patch) | |
| tree | 0b6ad736ec9cfd33e5678a8d437a30c444072455 /web/discordwebhook/webhook.go | |
| parent | 75c6b7060169f84f88e27c277edbcbfa739d7f54 (diff) | |
| download | x-b395841f422fd9c6e50b4be979da0f308f9499a9.tar.xz x-b395841f422fd9c6e50b4be979da0f308f9499a9.zip | |
web: try using exp/errors, error type for API calls
Diffstat (limited to 'web/discordwebhook/webhook.go')
| -rw-r--r-- | web/discordwebhook/webhook.go | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/web/discordwebhook/webhook.go b/web/discordwebhook/webhook.go index 152ec74..a5dc1fc 100644 --- a/web/discordwebhook/webhook.go +++ b/web/discordwebhook/webhook.go @@ -1,11 +1,13 @@ +// Package discordwebhook is a simple low-level HTTP client wrapper around Discord webhooks. package discordwebhook import ( "bytes" "encoding/json" - "fmt" "io/ioutil" "net/http" + + "github.com/Xe/x/web" ) // Webhook is the parent structure fired off to Discord. @@ -64,7 +66,19 @@ func Validate(resp *http.Response) error { return err } resp.Body.Close() - return fmt.Errorf("status code was %v: %s", resp.StatusCode, string(data)) + + loc, err := resp.Location() + if err != nil { + return err + } + + return &web.Error{ + WantStatus: 200, + GotStatus: resp.StatusCode, + URL: loc, + Method: resp.Request.Method, + ResponseBody: string(data), + } } return nil |
