diff options
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, + } +} |
