-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
44 lines (37 loc) · 895 Bytes
/
errors.go
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
package qor
import "strings"
// Errors is a struct that used to hold errors array
type Errors struct {
errors []error
}
// Error get formatted error message
func (errs Errors) Error() string {
var errors []string
for _, err := range errs.errors {
errors = append(errors, err.Error())
}
return strings.Join(errors, "; ")
}
// AddError add error to Errors struct
func (errs *Errors) AddError(errors ...error) {
for _, err := range errors {
if err != nil {
if e, ok := err.(errorsInterface); ok {
errs.errors = append(errs.errors, e.GetErrors()...)
} else {
errs.errors = append(errs.errors, err)
}
}
}
}
// HasError return has error or not
func (errs Errors) HasError() bool {
return len(errs.errors) != 0
}
// GetErrors return error array
func (errs Errors) GetErrors() []error {
return errs.errors
}
type errorsInterface interface {
GetErrors() []error
}