-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
33 lines (28 loc) · 769 Bytes
/
error.go
File metadata and controls
33 lines (28 loc) · 769 Bytes
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
package rmhttp
import (
"fmt"
)
// An HTTPError represents an error with an additional HTTP status code
type HTTPError struct {
Err error
Code int
}
// NewHTTPError creates and returns a new, initialised pointer to a HTTPError
func NewHTTPError(err error, code int) HTTPError {
return HTTPError{
Err: err,
Code: code,
}
}
// Unwrap returns the underlying Error that this HTTPError wraps.
//
// This method allows an HTTPError to be used by errors.Is().
func (e HTTPError) Unwrap() error {
return e.Err
}
// Error returns the error text of the receiver HTTPError as a string.
//
// This method allows HTTPError to implement the standard library Error interface.
func (e HTTPError) Error() string {
return fmt.Sprintf("%d: %s", e.Code, e.Err.Error())
}