-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
41 lines (32 loc) · 847 Bytes
/
errors.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
35
36
37
38
39
40
41
package auth
import (
"errors"
)
// Error is the base error type. The builder pattern is used to add specialization codes to the errors.
type Error struct {
Message string
Code int
}
// Check to ensure the error interface is implemented.
var _ error = &Error{}
// Error get human readable error message.
func (e *Error) Error() string {
return e.Message
}
// Is will return whether the input err is an instance of expected error.
func (e *Error) Is(err error) bool {
var target *Error
if !errors.As(err, &target) {
return false
}
return e.Code == target.Code
}
// NewError is a base error message with no special code.
func NewError(message string) *Error {
return &Error{Message: message, Code: 0}
}
// SetStatus configures the error status/code.
func (e *Error) SetStatus(status int) *Error {
e.Code = status
return e
}