Skip to content

Add additional error information #10

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

Merged
merged 10 commits into from
Mar 5, 2019
Merged

Add additional error information #10

merged 10 commits into from
Mar 5, 2019

Conversation

lpatino10
Copy link
Contributor

An issue was submitted a while back where users using a certain API couldn't retrieve a correlation_id field in their error response due to the way we were handling and wrapping errors. This field was particularly important for support people trying to resolve errors.

This PR changes the main exception class ServiceResponseException to handle parsing for error messages, which used to be done in WatsonService it also changes what is provided for the user, removing the raw Response object in favor of message (the parsed error message) and debuggingInfo, which is a Map of the rest of the response.

A test has been added to validate the debugging information.

@germanattanasio
Copy link
Contributor

germanattanasio commented Mar 5, 2019

I quickly looked at the PR and have 2 questions

  • Can you get the response body even if it doesn't match the classic error or error_message or message json response?
  • Can you get ALL the response headers?

@lpatino10
Copy link
Contributor Author

Good questions. I just made some changes so here are the answers:

  1. If we can't parse the error message by looking for error, error_message, or message, we'll supply a default error message. These are the same as before.
  2. I just added a getHeaders() method to the ServiceResponseException class to get an instance of our custom Headers class. All other body info will be in debuggingInfo.

@padamstx
Copy link
Member

padamstx commented Mar 5, 2019

by looking for error, error_message, or message

IIRC, this is the set of properties that needs to be commonized across all the languages, per https://github.ibm.com/arf/planning-sdk-squad/issues/818

@lpatino10
Copy link
Contributor Author

Yep, those are the ones @padamstx. I'll send a message out about those now and we can hold off on merging this if you want until we get that coordinated.

@germanattanasio
Copy link
Contributor

@lpatino10 some services like Discovery return an errors array with Error objects. Is this taking that case into account?

@padamstx
Copy link
Member

padamstx commented Mar 5, 2019

I think we can go ahead and merge this PR now. We just need to remember to update the other core packages to use the same common set of response property names.

padamstx
padamstx previously approved these changes Mar 5, 2019
Copy link
Member

@padamstx padamstx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just one comment to think about.

String responseString = ResponseUtils.getString(response);
try {
final JsonObject jsonObject = ResponseUtils.getJsonObject(responseString);
if (jsonObject.has(MESSAGE_ERROR)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be cleaner if the various MESSAGE_ERROR* constants were just a String[] where the elements are an ordered list of the property names that we'll look for. Then the various if/elseif/.../else blocks would become a loop over the elements in the array and we just bail out after finding the first match. This way, when (and I mean when) the list of properties changes, it will be easy to change them :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does sound cleaner. I'll make that change along with (maybe) the one to handle the new error spec.

@lpatino10
Copy link
Contributor Author

@germanattanasio are you talking about this spec?: https://pages.github.ibm.com/CloudEngineering/api_handbook/design/errors.html

Taj just sent me that and I'm not sure if we have other SDKs specifically handling it. We can add that for the major release though.

germanattanasio
germanattanasio previously approved these changes Mar 5, 2019
Copy link
Contributor

@germanattanasio germanattanasio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@lpatino10 lpatino10 dismissed stale reviews from germanattanasio and padamstx via 8c2f7d5 March 5, 2019 19:49
Copy link
Member

@padamstx padamstx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lpatino10 lpatino10 merged commit 47b8546 into master Mar 5, 2019
@lpatino10 lpatino10 deleted the error-debug-info branch March 5, 2019 21:09
@mkistler
Copy link
Contributor

mkistler commented Mar 6, 2019

Regarding:

some services like Discovery return an errors array with Error objects.

I have complained about this design, which is actually the recommended approach in the API Handbook, since I first saw it. I think this form of error response is wrong-headed. The rationale is that there could be multiple errors and we should report all of them on the response. But then how do we convert this into a meaningful error that software can process?

cc: @jsstylos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants