-
Notifications
You must be signed in to change notification settings - Fork 2
Improve error messages #168
Comments
Metal Errors are returned as such:
and sometimes: In the OAS3 spec, we have the Error type defined: https://github.com/equinix-labs/metal-go/blob/b1e03ba5195bd47eed1dd3db3ce38d2b494b349f/spec/oas3.fetched/components/schemas/Error.yaml This renders to model_error.go That type does not implement If we created a separate // copyrights
package v1
func (o *Error) Error() string {
errs := []string{}
errs = append(errs, r.Errors...)
if r.Error != "" {
errs = append(errs, r.Error)
}
return strings.Join(errs, ", ")
} Inside of if err, ok := v.(error); ok {
str = err.Error()
} (We could consider removing the RFC-7807 handling portion since that was generic and not implemented in this API) |
I'm not sure we get much out of patching the |
This updates the `formatErrorMessage` helper so that, if the API responded with an Error model, the messages from that Error model are appended to the status code & status description. This makes it easier for users to get visibility into why an API call failed. I chose to leave the existing code to support rfc7807 messages in place, just in case we ever migrate to that standard. Fixes #168
This issue has been resolved in version 0.26.0 🎉 |
Today the error messages emitted only report the HTTP Status message.
422 Unrecognized Entities
https://github.com/equinix-labs/metal-go/blob/main/metal/v1/api_projects.go#L175
metal-go/templates/client.mustache
Lines 736 to 754 in b1e03ba
https://www.rfc-editor.org/rfc/rfc7807#section-3
In packngo the possible error bodies were converted into the error message returned, along with the HTTP status message.
422 Unrecognized Entities: foo is not valid with bar, baz is required
https://github.com/packethost/packngo/blob/master/packngo.go#L71-L81
metal-go (arguably all of the generated SDKs) should offer some examples and improved experience around accessing the reported error message(s).
The text was updated successfully, but these errors were encountered: