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/error.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/error.go')
| -rw-r--r-- | web/error.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/web/error.go b/web/error.go new file mode 100644 index 0000000..e4ffcab --- /dev/null +++ b/web/error.go @@ -0,0 +1,33 @@ +// Package web is a simple collection of high-level error and transport types +// that I end up using over and over. +package web + +import ( + "fmt" + "net/url" + + "within.website/ln" +) + +// Error is an API error. +type Error struct { + WantStatus, GotStatus int + URL *url.URL + Method string + ResponseBody string +} + +func (e Error) Error() string { + return fmt.Sprintf("%s %s: wanted status code %d, got: %d: %v", e.Method, e.URL, e.WantStatus, e.GotStatus, e.ResponseBody) +} + +// F ields for logging. +func (e Error) F() ln.F { + return ln.F{ + "err_want_status": e.WantStatus, + "err_got_status": e.GotStatus, + "err_url": e.URL, + "err_method": e.Method, + "err_response_body": e.ResponseBody, + } +} |
