Add errorsInterface
This commit is contained in:
parent
0996ddb604
commit
dd0d4d931f
@ -13,6 +13,10 @@ var (
|
||||
CantStartTransaction = errors.New("can't start transaction")
|
||||
)
|
||||
|
||||
type errorsInterface interface {
|
||||
GetErrors() []error
|
||||
}
|
||||
|
||||
type Errors struct {
|
||||
errors []error
|
||||
}
|
||||
|
13
main.go
13
main.go
@ -518,18 +518,23 @@ func (s *DB) AddError(err error) error {
|
||||
s.log(err)
|
||||
}
|
||||
|
||||
if e, ok := err.(errorsInterface); ok {
|
||||
err = Errors{errors: append(s.GetErrors(), e.GetErrors()...)}
|
||||
} else {
|
||||
err = Errors{errors: append(s.GetErrors(), err)}
|
||||
}
|
||||
}
|
||||
|
||||
s.Error = err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *DB) GetErrors() []error {
|
||||
if errs, ok := s.Error.(Errors); ok {
|
||||
return errs.errors
|
||||
} else {
|
||||
func (s *DB) GetErrors() (errors []error) {
|
||||
if errs, ok := s.Error.(errorsInterface); ok {
|
||||
return errs.GetErrors()
|
||||
} else if s.Error != nil {
|
||||
return []error{s.Error}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user