-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_errors.go
More file actions
41 lines (36 loc) · 787 Bytes
/
app_errors.go
File metadata and controls
41 lines (36 loc) · 787 Bytes
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
package goapperrors
import (
"errors"
"strings"
)
// AppErrors is a defined type of slice of AppError
type AppErrors []AppError
// Error implements `error` interface
func (aes AppErrors) Error() string {
var sb strings.Builder
for i, err := range aes {
if i > 0 {
sb.WriteString(globalConfig.MultiErrorSeparator)
}
sb.WriteString(err.Error())
}
return sb.String()
}
// Is implementation used by errors.Is()
func (aes AppErrors) Is(err error) bool {
for _, e := range aes {
if errors.Is(e, err) {
return true
}
}
return false
}
// Unwrap implementation used by errors.Is().
// errors.Unwrap() only works with `Unwrap() error`.
func (aes AppErrors) Unwrap() []error {
ret := make([]error, len(aes))
for i, err := range aes {
ret[i] = err
}
return ret
}