-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_error.go
48 lines (40 loc) · 908 Bytes
/
base_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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package baseerror
import (
"errors"
"fmt"
)
type BaseError struct {
error
}
var (
ErrAlreadyExists = NewError("already exists")
ErrFailedPrecondition = NewError("failed precondition")
ErrInvalidArgument = NewError("invalid argument")
ErrNotFound = NewError("not found")
ErrOutOfRange = NewError("out of range")
ErrPermissionDenied = NewError("permission denied")
ErrUnauthenticated = NewError("unauthenticated")
)
func NewError(text string) BaseError {
return BaseError{
error: errors.New(text),
}
}
func WrapError(err error) BaseError {
return BaseError{
error: err,
}
}
func (be BaseError) Unwrap() error {
return be.error
}
func (be BaseError) Wrap(text string) BaseError {
return BaseError{
error: fmt.Errorf("%w: %v", be, text),
}
}
func (be BaseError) WrapError(err error) BaseError {
return BaseError{
error: errors.Join(be, err),
}
}