-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
59 lines (48 loc) · 1.6 KB
/
types.go
File metadata and controls
59 lines (48 loc) · 1.6 KB
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
// Copyright 2024 FishGoddess. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package errors
const (
codeBadRequest = 400
codeForbidden = 403
codeNotFound = 404
)
// BadRequest returns *Error with bad request code.
func BadRequest(message string, args ...any) *Error {
return Wrap(codeBadRequest, message, args...)
}
// Forbidden returns *Error with forbidden code.
func Forbidden(message string, args ...any) *Error {
return Wrap(codeForbidden, message, args...)
}
// NotFound returns *Error with not found code.
func NotFound(message string, args ...any) *Error {
return Wrap(codeNotFound, message, args...)
}
// IsBadRequest checks err with bad request code.
func IsBadRequest(err error) bool {
return IsCode(err, codeBadRequest)
}
// IsForbidden checks err with forbidden code.
func IsForbidden(err error) bool {
return IsCode(err, codeForbidden)
}
// IsNotFound checks err with not found code.
func IsNotFound(err error) bool {
return IsCode(err, codeNotFound)
}
// MatchBadRequest matches err with bad request code.
// Deprecated: Use IsBadRequest instead because this name is 'ugly' to me.
func MatchBadRequest(err error) bool {
return IsBadRequest(err)
}
// MatchForbidden matches err with forbidden code.
// Deprecated: Use IsForbidden instead because this name is 'ugly' to me.
func MatchForbidden(err error) bool {
return IsForbidden(err)
}
// MatchNotFound matches err with not found code.
// Deprecated: Use IsNotFound instead because this name is 'ugly' to me.
func MatchNotFound(err error) bool {
return IsNotFound(err)
}