-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
109 lines (91 loc) · 3.75 KB
/
helpers.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package errutil
// NewAccessDenied creates a new error and gives it AccessDenier behavior
func NewAccessDenied(msg string, opts ...OptsFunc) error {
opts = append(opts, WithStackTrace(1), WithAccessDenied())
return New(msg, opts...)
}
// WrapAccessDenied wraps an error and gives it AccessDenier behavior
func WrapAccessDenied(err error, opts ...OptsFunc) error {
opts = append(opts, WithStackTrace(1), WithAccessDenied())
return Wrap(err, opts...)
}
// NewExists creates a new error and gives it Exister behavior
func NewExists(msg string, opts ...OptsFunc) error {
opts = append(opts, WithStackTrace(1), WithExists())
return New(msg, opts...)
}
// WrapExists wraps an error and gives it Exister behavior
func WrapExists(err error, opts ...OptsFunc) error {
opts = append(opts, WithStackTrace(1), WithExists())
return Wrap(err, opts...)
}
// NewConflict creates a new error and gives it Conflicter behavior
func NewConflict(msg string, opts ...OptsFunc) error {
opts = append(opts, WithStackTrace(1), WithConflict())
return New(msg, opts...)
}
// WrapConflict wraps an error and gives it Conflicter behavior
func WrapConflict(err error, opts ...OptsFunc) error {
opts = append(opts, WithStackTrace(1), WithConflict())
return Wrap(err, opts...)
}
// NewNotFound creates a new error and gives it NotFounder behavior
func NewNotFound(msg string, opts ...OptsFunc) error {
opts = append(opts, WithStackTrace(1), WithNotFound())
return New(msg, opts...)
}
// WrapNotFound wraps an error and gives it NotFounder behavior
func WrapNotFound(err error, opts ...OptsFunc) error {
opts = append(opts, WithStackTrace(1), WithNotFound())
return Wrap(err, opts...)
}
// NewRateLimit creates a new error and gives it RateLimiter behavior
func NewRateLimit(msg string, opts ...OptsFunc) error {
opts = append(opts, WithStackTrace(1), WithRateLimit())
return New(msg, opts...)
}
// WrapRateLimit wraps an error and gives it RateLimiter behavior
func WrapRateLimit(err error, opts ...OptsFunc) error {
opts = append(opts, WithStackTrace(1), WithRateLimit())
return Wrap(err, opts...)
}
// NewTemporary creates a new error and gives it Temporarily behavior
func NewTemporary(msg string, opts ...OptsFunc) error {
opts = append(opts, WithStackTrace(1), WithTemporary())
return New(msg, opts...)
}
// WrapTemporary wraps an error and gives it Temporarily behavior
func WrapTemporary(err error, opts ...OptsFunc) error {
opts = append(opts, WithStackTrace(1), WithTemporary())
return Wrap(err, opts...)
}
// NewTooLarge creates a new error and gives it TooLarge behavior
func NewTooLarge(msg string, opts ...OptsFunc) error {
opts = append(opts, WithStackTrace(1), WithTooLarge())
return New(msg, opts...)
}
// WrapTooLarge wraps an error and gives it TooLarge behavior
func WrapTooLarge(err error, opts ...OptsFunc) error {
opts = append(opts, WithStackTrace(1), WithTooLarge())
return Wrap(err, opts...)
}
// NewTooManyRequests creates a new error and gives it TooManyRequester behavior
func NewTooManyRequests(msg string, opts ...OptsFunc) error {
opts = append(opts, WithStackTrace(1), WithTooManyRequests())
return New(msg, opts...)
}
// WrapTooManyRequests wraps an error and gives it TooManyRequester behavior
func WrapTooManyRequests(err error, opts ...OptsFunc) error {
opts = append(opts, WithStackTrace(1), WithTooManyRequests())
return Wrap(err, opts...)
}
// NewUnauthorized creates a new error and gives it Unauthorizable behavior
func NewUnauthorized(msg string, opts ...OptsFunc) error {
opts = append(opts, WithStackTrace(1), WithUnauthorized())
return New(msg, opts...)
}
// WrapUnauthorized wraps an error and gives it Unauthorizable behavior
func WrapUnauthorized(err error, opts ...OptsFunc) error {
opts = append(opts, WithStackTrace(1), WithUnauthorized())
return Wrap(err, opts...)
}