-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherr.go
More file actions
36 lines (28 loc) · 813 Bytes
/
err.go
File metadata and controls
36 lines (28 loc) · 813 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
package statuserr
import "fmt"
type err struct {
StatusCode int
Message string
}
// New returns a new status err with a status code
func New(code int, message string) error {
return err{StatusCode: code, Message: message}
}
// Wrap an existing error with the status code
// BadRequest.Wrap(errors.New("bad user request"))
func (e err) Wrap(new error) error {
return err{StatusCode: e.Status(), Message: new.Error()}
}
func (e err) Error() string {
return e.Message
}
// Status returns the status code associated with the error
func (e err) Status() int {
return e.StatusCode
}
func (e err) Msg(m string) error {
return err{StatusCode: e.Status(), Message: m}
}
func (e err) Msgf(format string, a ...interface{}) error {
return err{StatusCode: e.Status(), Message: fmt.Sprintf(format, a...)}
}