Skip to content

Commit 8743d3e

Browse files
committed
添加资源已存在异常
1 parent 0257070 commit 8743d3e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

exception/exception.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ func NewNotFound(format string, a ...interface{}) APIException {
6363
return newException(usedNamespace, NotFound, format, a...)
6464
}
6565

66+
// NewConflict todo
67+
func NewConflict(format string, a ...interface{}) APIException {
68+
return newException(usedNamespace, Conflict, format, a...)
69+
}
70+
6671
// NewInternalServerError 500
6772
func NewInternalServerError(format string, a ...interface{}) APIException {
6873
return newException(usedNamespace, InternalServerError, format, a...)
@@ -81,3 +86,17 @@ func IsNotFoundError(err error) bool {
8186

8287
return e.ErrorCode() == NotFound && e.Namespace() == GlobalNamespace.String()
8388
}
89+
90+
// IsConflictError 判断是否是Conflict
91+
func IsConflictError(err error) bool {
92+
if err == nil {
93+
return false
94+
}
95+
96+
e, ok := err.(APIException)
97+
if !ok {
98+
return false
99+
}
100+
101+
return e.ErrorCode() == Conflict && e.Namespace() == GlobalNamespace.String()
102+
}

0 commit comments

Comments
 (0)