|
1 | 1 | package exception |
2 | 2 |
|
3 | | -import "fmt" |
4 | | - |
5 | 3 | // NewUnauthorized 未认证 |
6 | 4 | func NewUnauthorized(format string, a ...interface{}) APIException { |
7 | | - return &exception{ |
8 | | - msg: fmt.Sprintf(format, a...), |
9 | | - code: Unauthorized, |
10 | | - } |
| 5 | + return newException(usedNamespace, Unauthorized, codeReason(Unauthorized), format, a...) |
11 | 6 | } |
12 | 7 |
|
13 | 8 | // NewPermissionDeny 没有权限访问 |
14 | 9 | func NewPermissionDeny(format string, a ...interface{}) APIException { |
15 | | - return &exception{ |
16 | | - msg: fmt.Sprintf(format, a...), |
17 | | - code: Forbidden, |
18 | | - } |
| 10 | + return newException(usedNamespace, Forbidden, codeReason(Forbidden), format, a...) |
19 | 11 | } |
20 | 12 |
|
21 | 13 | // NewTokenExpired token过期 |
22 | 14 | func NewTokenExpired(format string, a ...interface{}) APIException { |
23 | | - return &exception{ |
24 | | - msg: fmt.Sprintf(format, a...), |
25 | | - code: TokenExpired, |
26 | | - } |
| 15 | + return newException(usedNamespace, TokenExpired, codeReason(TokenExpired), format, a...) |
27 | 16 | } |
28 | 17 |
|
29 | 18 | // NewBadRequest todo |
30 | 19 | func NewBadRequest(format string, a ...interface{}) APIException { |
31 | | - return &exception{ |
32 | | - msg: fmt.Sprintf(format, a...), |
33 | | - code: BadRequest, |
34 | | - } |
| 20 | + return newException(usedNamespace, BadRequest, codeReason(BadRequest), format, a...) |
35 | 21 | } |
36 | 22 |
|
37 | 23 | // NewNotFound todo |
38 | 24 | func NewNotFound(format string, a ...interface{}) APIException { |
39 | | - return &exception{ |
40 | | - msg: fmt.Sprintf(format, a...), |
41 | | - code: NotFound, |
42 | | - } |
| 25 | + return newException(usedNamespace, NotFound, codeReason(BadRequest), format, a...) |
43 | 26 | } |
44 | 27 |
|
45 | 28 | // NewInternalServerError 500 |
46 | 29 | func NewInternalServerError(format string, a ...interface{}) APIException { |
47 | | - return &exception{ |
48 | | - msg: fmt.Sprintf(format, a...), |
49 | | - code: InternalServerError, |
50 | | - } |
| 30 | + return newException(usedNamespace, InternalServerError, codeReason(InternalServerError), format, a...) |
51 | 31 | } |
52 | 32 |
|
53 | 33 | // IsNotFoundError 判断是否是NotFoundError |
|
0 commit comments