diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-03-11 13:52:49 +0100 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-04-05 12:26:14 +0200 |
| commit | a019e95fdbaea3d7af2d8ad10903fd656bfc4466 (patch) | |
| tree | 4e852e36da327823a02678dfb766aca58fa0a23f /src/error.go | |
| parent | 5065de4cff907b70ea3446888a7bad243744a8ab (diff) | |
Refactor: Simplify errors for wrapping
Diffstat (limited to 'src/error.go')
| -rw-r--r-- | src/error.go | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/src/error.go b/src/error.go index 87d7e53..13803cc 100644 --- a/src/error.go +++ b/src/error.go @@ -1,30 +1,42 @@ package eduvpn -type detailedVPNErrorCode int8 -type VPNErrorCode int8 +import "fmt" -type VPNError struct { - Code VPNErrorCode - Detailed detailedVPNError +// Error structures defined here are used throughout the code + +type HTTPResourceError struct { + URL string + Err error +} + +func (e *HTTPResourceError) Error() string { + return fmt.Sprintf("failed obtaining HTTP resource %s with error %v", e.URL, e.Err) } -func (err VPNError) Error() string { - return err.Detailed.Error() +type HTTPStatusError struct { + URL string + Status int } -func (err VPNError) Unwrap() error { - return err.Detailed +func (e *HTTPStatusError) Error() string { + return fmt.Sprintf("failed obtaining HTTP resource %s as it gave an unsuccesful status code %d", e.URL, e.Status) } -type detailedVPNError struct { - Code detailedVPNErrorCode - Message string - Cause error +type HTTPReadError struct { + URL string + Err error } -func (err detailedVPNError) Error() string { - return err.Message +func (e *HTTPReadError) Error() string { + return fmt.Sprintf("failed reading HTTP resource %s with error %v", e.URL, e.Err) } -func (err detailedVPNError) Unwrap() error { - return err.Cause + +type HTTPParseJsonError struct { + URL string + Body string + Err error +} + +func (e *HTTPParseJsonError) Error() string { + return fmt.Sprintf("failed parsing json %s for HTTP resource %s with error %v", e.Body, e.URL, e.Err) } |
