-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API error responses no longer contain error code explanations #327
Comments
@metskem I can take a look at that this week. Alternatively, if you're able to dig-in and raise a PR against the Separately/In the mean time, are you able to use the Also, v1.4.0 is only a few days old and this new API error handling was added then. |
Actually, the |
I can use APIError like in
But then still I don't know how to get the detailed error explanation (I might be missing something here). |
@metskem Assuming we are inside of that if aerr.APIError.Valid {
fmt.Printf"top-level error message and code: %s (%d)\n", aerr.APIError.ErrorObject.Message, aerr.APIError.ErrorObject.Code)
// get all error strings
for i, errStr := range aerr.APIError.ErrorObject.Errors {
fmt.Printf("error %d: %s\n", i, errStr)
}
} As of this moment, the error string printed does not include those additional error strings from the API. We could capture the first error string in the response, but it'd still be on consumers to pick the error apart and show the rest. |
That works perfect Tim. Thanks for the quick response, I appreciate. |
While refactoring the API handling with the `APIError` type, we gave callers more capability to inspect the errors that come from the API so that we can handle them. Unfortunately, in the process we lost some fidelity in the strings returned by its `Error()` method, compared to how errors used to be handled. This updates the `APIError.Error()` method to now include the first detailed error string provided from the API, if there is one, and incidate how many more existed in the response (without printing them). This should help keep the error tidy, while making it actionable by consumers. Consumers of this package are still encouraged to deeply inspect the error, to handle each one. This was inspired by #327, which the reported closed after learning how to deeply inspect the returned error value.
While refactoring the API handling with the `APIError` type, we gave callers more capability to inspect the errors that come from the API so that we can handle them. Unfortunately, in the process we lost some fidelity in the strings returned by its `Error()` method, compared to how errors used to be handled. This updates the `APIError.Error()` method to now include the first detailed error string provided from the API, if there is one, and incidate how many more existed in the response (without printing them). This should help keep the error tidy, while making it actionable by consumers. Consumers of this package are still encouraged to deeply inspect the error, to handle each one. This was inspired by #327, which the reporter closed after learning how to deeply inspect the returned error value.
I raised #334, which should help add some fidelity back to the error strings. It'll be part of |
A couple of months ago I updated to the 1.4.0 release of the pagerduty golang library.
I noticed that error responses now have become more cryptic, and leaves us basically in the dark.
I have 2 examples with the response from 1.3.0 and 1.4.0:
1.3.0:
Failed call API endpoint. HTTP response code: 400. Error: &{2001 Invalid Input Provided [User cannot be removed as they belong to an escalation policy on this team]}
1.4.0:
HTTP response failed with status code 400, message: Invalid Input Provided (code: 2001)
1.3.0:
Failed call API endpoint. HTTP response code: 400. Error: &{2001 Invalid Input Provided [User cannot be removed as they belong to an escalation policy on this team]}
1.4.0:
HTTP response failed with status code 400, message: Invalid Input Provided (code: 2001)
So basically, both errors are summarized as "Invalid Input Provided (code: 2001)", which leaves us clueless.
For now I reverted back to 1.3.0 (we were not yet using Tag support).
Would it be possible to fix this, and give more clear error responses again?
The text was updated successfully, but these errors were encountered: