Skip to content

Commit

Permalink
add MultiError type (micro#2297)
Browse files Browse the repository at this point in the history
  • Loading branch information
Qalifah authored Oct 6, 2021
1 parent 2ef523a commit a99a1e9
Show file tree
Hide file tree
Showing 7 changed files with 302 additions and 74 deletions.
19 changes: 19 additions & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,22 @@ func As(err error) (*Error, bool) {
}
return nil, false
}

func NewMultiError() *MultiError {
return &MultiError{
Errors: make([]*Error, 0),
}
}

func (e *MultiError) Append(err *Error) {
e.Errors = append(e.Errors, err)
}

func (e *MultiError) HasErrors() bool {
return len(e.Errors) > 0
}

func (e *MultiError) Error() string {
b, _ := json.Marshal(e)
return string(b)
}
263 changes: 197 additions & 66 deletions errors/errors.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 2 additions & 8 deletions errors/errors.pb.micro.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions errors/errors.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ message Error {
string detail = 3;
string status = 4;
};

message MultiError {
repeated Error errors = 1;
}
Loading

0 comments on commit a99a1e9

Please sign in to comment.