Skip to content
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

pds api 127: improved error messaging #95

Merged
merged 2 commits into from
Mar 1, 2022
Merged

pds api 127: improved error messaging #95

merged 2 commits into from
Mar 1, 2022

Conversation

al-niessner
Copy link
Contributor

🗒️ Summary

Changed all of the AcceptTypeException to return 406 instead of 501.

Improved the message for the exception to include all of the known Accept: content types allowed.

Note, if a Accept: content type is not supported, then the result always comes out as JSON. If the request was 'Accept: text/htlm' then the chosen serializer is JSON.

⚙️ Test Data and/or Report

$ curl --location --request GET 'http://localhost:8080/products/urn:nasa:pds:izenberg_pdart14_meap:document:ns_ins::1.0' --header 'Accept: text/html'
<html><body><h1>Error Message</h1><h2>From Request</h2><p>/products/urn:nasa:pds:izenberg_pdart14_meap:document:ns_ins::1.0</p><h2>Message</h2><p>The lidvid urn:nasa:pds:izenberg_pdart14_meap:document:ns_ins was not found</p></body></html>
$ curl --location --request GET 'http://localhost:8080/products/urn:nasa:pds:izenberg_pdart14_meap:document:ns_inst::1.0' --header 'Accept: text/htmls'
{"request":"/products/urn:nasa:pds:izenberg_pdart14_meap:document:ns_inst::1.0","message":"The given application type, text/htmls, is not known by RquestAndResponseContext. Known choices are: application/csv,application/xml,text/html,application/json,*/*,application/pds4+xml,text/csv,text/xml,application/kvp+json,application/pds4+json"}

♻️ Related Issues

#446

Changed all of the AcceptTypeException to return 406 instead of 501.

Improved the message for the exception to include all of the known Accept: content types allowed.
@al-niessner
Copy link
Contributor Author

@tloubrieu-jpl @jordanpadams

Ready for review.

Copy link
Member

@tloubrieu-jpl tloubrieu-jpl left a comment

Choose a reason for hiding this comment

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

Thanks @al-niessner , that works well. the most critical comment is how the message shows to the user.

throw new ApplicationTypeException("The given application type, " + String.valueOf(this.format) + ", is not known by RquestAndResponseContext.");
for (String key : this.formatters.keySet())
{
log.warn(" key: " + String.valueOf(key));
Copy link
Member

Choose a reason for hiding this comment

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

Do we need a warning for this message ? I would think of DEBUG, unless I misunderstood what it does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need in what way? Will the program work without the warning, yes. When a user says they got a 406 on Saturday will you be able to find it in the log if not posted, no. So define what you mean by need.

Warnings are usually issued when the program detects something fishy (a handled exception) notifying the initiator of the fishy bit that something looks wrong but was handled albeit maybe not how the initiator wanted so they may want to try again -- think or google compiler warnings. Warnings differs from errors in that the program does not crash and burn. Debug on the other hand is way of tracing the program to determine where a bug is hiding or may exist or prove its existance.

For this message when a user mentions days later that a 406 was returned (something fishy but handled) we would have the appropriate level of logging.

If you want it to be debug then simply say so directly and I will change it. One could argue that given errors are being returned to the user the logging is superfluous.

Copy link
Member

@tloubrieu-jpl tloubrieu-jpl left a comment

Choose a reason for hiding this comment

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

Thanks Al, I will merge it.

@tloubrieu-jpl tloubrieu-jpl merged commit 13df0ce into main Mar 1, 2022
@tloubrieu-jpl tloubrieu-jpl deleted the pds-api-127 branch March 1, 2022 18:27
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.

2 participants