-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
37 lines (31 loc) · 752 Bytes
/
errors.go
File metadata and controls
37 lines (31 loc) · 752 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
34
35
36
37
package amaro
import (
"fmt"
"net/http"
)
// HTTPError represents an error with an associated HTTP status code.
type HTTPError struct {
Code int
Message interface{}
Internal error
}
func (e *HTTPError) Error() string {
return fmt.Sprintf("code=%d, message=%v", e.Code, e.Message)
}
// NewHTTPError creates a new HTTPError.
func NewHTTPError(code int, message ...interface{}) *HTTPError {
he := &HTTPError{Code: code, Message: http.StatusText(code)}
if len(message) > 0 {
he.Message = message[0]
}
return he
}
// SetInternal sets the internal error.
func (e *HTTPError) SetInternal(err error) *HTTPError {
e.Internal = err
return e
}
// Unwrap returns the internal error.
func (e *HTTPError) Unwrap() error {
return e.Internal
}