-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
52 lines (41 loc) · 1.05 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
package model
import (
"errors"
"strings"
)
var (
ErrInvalid = errors.New("invalid")
ErrUnauthorized = errors.New("unauthorized")
ErrForbidden = errors.New("forbidden")
ErrNotFound = errors.New("not found")
ErrMethodNotAllowed = errors.New("method not allowed")
ErrInternalError = errors.New("internal error")
)
func WrapInvalid(err error) error {
return errors.Join(err, ErrInvalid)
}
func WrapUnauthorized(err error) error {
return errors.Join(err, ErrUnauthorized)
}
func WrapForbidden(err error) error {
return errors.Join(err, ErrForbidden)
}
func WrapNotFound(err error) error {
return errors.Join(err, ErrNotFound)
}
func WrapMethodNotAllowed(err error) error {
return errors.Join(err, ErrMethodNotAllowed)
}
func WrapInternal(err error) error {
return errors.Join(err, ErrInternalError)
}
func ConcatError(errs []error) error {
if len(errs) == 0 {
return nil
}
values := make([]string, len(errs))
for index, err := range errs {
values[index] = err.Error()
}
return errors.New(strings.Join(values, ", "))
}