Skip to content

Commit

Permalink
Add more error handling helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanvanderbyl committed May 25, 2022
1 parent c38f55d commit a5c2b0c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,24 @@ const (
UnsupportedVersion ErrorCode = "unsupported_version"
)

// IsErrorCode is a concenience method to check if an error is a specific error code from Duffel.
// This simplifies error handling branches without needing to type cast multiple times in your code.
func IsErrorCode(err error, code ErrorCode) bool {
if err, ok := err.(*DuffelError); ok {
return err.IsCode(code)
}
return false
}

// IsErrorType is a concenience method to check if an error is a specific error type from Duffel.
// This simplifies error handling branches without needing to type cast multiple times in your code.
func IsErrorType(err error, typ ErrorType) bool {
if err, ok := err.(*DuffelError); ok {
return err.IsType(typ)
}
return false
}

type DuffelError struct {
Meta ErrorMeta `json:"meta"`
Errors []Error `json:"errors"`
Expand Down

0 comments on commit a5c2b0c

Please sign in to comment.