-
Notifications
You must be signed in to change notification settings - Fork 90
/
fetch_error.go
34 lines (29 loc) · 833 Bytes
/
fetch_error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main
import "fmt"
// We define a custom error type so that we can provide friendlier error messages
type FetchError struct {
errorCode int // an error code is an arbitrary int that allows for strongly typed identification of specific errors
details string // the output of the underlying error message, if any
err error // the underlying golang error, if any
}
// Implement the golang Error interface
func (e *FetchError) Error() string {
return fmt.Sprintf("%d - %s", e.errorCode, e.details)
}
func newError(errorCode int, details string) *FetchError {
return &FetchError{
errorCode: errorCode,
details: details,
err: nil,
}
}
func wrapError(err error) *FetchError {
if err == nil {
return nil
}
return &FetchError{
errorCode: -1,
details: err.Error(),
err: err,
}
}