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

Make endpoints return more helpful json decode failures #454

Merged
merged 2 commits into from
Nov 2, 2020

Conversation

jisantuc
Copy link
Contributor

@jisantuc jisantuc commented Oct 30, 2020

Overview

This PR makes endpoints return more helpful messages when JSON decoding fails. It overrides the method to create
messages from decode failures with special handling for circe decoding failures.

Checklist

  • New tests have been added or existing tests have been modified

Notes

Unfortunately this only returns the first error. I believe that this is because tapir just uses the decode function instead of the decodeAccumulating function for getting the circe decode result. We could also provide a closer derivation that would override this behavior.

Here are some example responses:

 $ echo '{}' | http :9090/collections/berlin/items
HTTP/1.1 400 Bad Request
Content-Length: 56
Content-Type: text/plain; charset=UTF-8
Date: Fri, 30 Oct 2020 21:26:22 GMT

I expected to find a value at .id, but there was nothing


 $ echo '{"id": 3}' | http :9090/collections/berlin/items
HTTP/1.1 400 Bad Request
Content-Length: 70
Content-Type: text/plain; charset=UTF-8
Date: Fri, 30 Oct 2020 21:26:33 GMT

I found something unexpected at .id. I expected a value of type String

Testing Instructions

  • start your server with transactions support -- ./scripts/server --with-transactions
  • send an obviously bogus request to the collections post endpoint: echo '{}' | http :9090/collections
  • correct the error it tells you about and send another post -- echo '{ YOUR CORRECTED JSON HERE }' | http :9090/collection
  • you should get different errors every time you do what the server asks you for until you end up with a valid collection

Closes #427

@kbgg
Copy link

kbgg commented Nov 2, 2020

Thanks again for this, works perfectly in my testing

@jisantuc jisantuc merged commit d112bc3 into master Nov 2, 2020
@jisantuc jisantuc deleted the feature/js/improve-error-messages-for-bad-requests branch November 2, 2020 17:32
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.

400 requests for transactions are very unhelpful
2 participants