File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,24 @@ const (
104104 UnsupportedVersion ErrorCode = "unsupported_version"
105105)
106106
107+ // IsErrorCode is a concenience method to check if an error is a specific error code from Duffel.
108+ // This simplifies error handling branches without needing to type cast multiple times in your code.
109+ func IsErrorCode (err error , code ErrorCode ) bool {
110+ if err , ok := err .(* DuffelError ); ok {
111+ return err .IsCode (code )
112+ }
113+ return false
114+ }
115+
116+ // IsErrorType is a concenience method to check if an error is a specific error type from Duffel.
117+ // This simplifies error handling branches without needing to type cast multiple times in your code.
118+ func IsErrorType (err error , typ ErrorType ) bool {
119+ if err , ok := err .(* DuffelError ); ok {
120+ return err .IsType (typ )
121+ }
122+ return false
123+ }
124+
107125type DuffelError struct {
108126 Meta ErrorMeta `json:"meta"`
109127 Errors []Error `json:"errors"`
You can’t perform that action at this time.
0 commit comments