maintain underlying error structs to allow for type conversion (#293)

* maintain underlying error structs to allow for type conversion and
defensive error checking

* allow Error.Is for Azure responses

* update readme, add tests to ensure type conversion

* fix whitespacing

* read me

* add import to readme example
This commit is contained in:
Quest Henkart
2023-05-04 02:48:59 +08:00
committed by GitHub
parent 24aa2005cc
commit a24581dce2
4 changed files with 46 additions and 10 deletions

View File

@@ -25,6 +25,10 @@ type ErrorResponse struct {
}
func (e *APIError) Error() string {
if e.HTTPStatusCode > 0 {
return fmt.Sprintf("error, status code: %d, message: %s", e.HTTPStatusCode, e.Message)
}
return e.Message
}
@@ -70,7 +74,7 @@ func (e *APIError) UnmarshalJSON(data []byte) (err error) {
}
func (e *RequestError) Error() string {
return fmt.Sprintf("status code %d, message: %s", e.HTTPStatusCode, e.Err)
return fmt.Sprintf("error, status code: %d, message: %s", e.HTTPStatusCode, e.Err)
}
func (e *RequestError) Unwrap() error {