Skip to content

Commit

Permalink
refactor: uniq sub error
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Apr 20, 2023
1 parent ff4cf8b commit 0492be9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
strategy:
matrix:
go:
- '1.20'
- '1.19'
- '1.18'
- '1.17'
Expand Down
17 changes: 17 additions & 0 deletions http_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ func (e *Error) AddExtra(key string, value interface{}) {
e.Extra[key] = value
}

// Exists return true if it already exists
func (e *Error) exists(he *Error) bool {
for _, item := range e.Errs {
if he.Title == item.Title &&
he.Message == item.Message &&
he.Category == item.Category {
return true
}
}
return false
}

// Add add error to error list
func (e *Error) Add(errs ...error) {
if len(errs) == 0 {
Expand All @@ -181,6 +193,11 @@ func (e *Error) Add(errs ...error) {
}
continue
}
// 判断是否已存在相同的error
// 如果已有相同error,则不添加
if e.exists(he) {
continue
}

e.Errs = append(e.Errs, he)
}
Expand Down

0 comments on commit 0492be9

Please sign in to comment.