add method to return MultiError or nil

This commit is contained in:
yuhanyang
2023-08-18 14:19:50 +08:00
parent 6a8462ca26
commit 7db3686711
2 changed files with 10 additions and 13 deletions

View File

@@ -941,10 +941,7 @@ check:
}
timeout.Stop()
if err.Error() == "[]" {
return nil
}
return err
return err.ErrorOrNil()
}
// Fork sends requests to all servers and Success once one server returns OK.
@@ -1040,11 +1037,7 @@ check:
}
timeout.Stop()
if err.Error() == "[]" {
return nil
}
return err
return err.ErrorOrNil()
}
// Inform sends requests to all servers and returns all results from services.
@@ -1154,10 +1147,7 @@ check:
}
timeout.Stop()
if err.Error() == "[]" {
return receipts, nil
}
return receipts, err
return receipts, err.ErrorOrNil()
}
// SendFile sends a local file to the server.

View File

@@ -22,6 +22,13 @@ func (e *MultiError) Append(err error) {
e.Errors = append(e.Errors, err)
}
func (e *MultiError) ErrorOrNil() error {
if e == nil || len(e.Errors) == 0 {
return nil
}
return e
}
// NewMultiError creates and returns an Error with error splice
func NewMultiError(errors []error) *MultiError {
return &MultiError{Errors: errors}