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

Handling invalid JSON bodies #31

Open
franzliedke opened this issue Nov 6, 2019 · 2 comments
Open

Handling invalid JSON bodies #31

franzliedke opened this issue Nov 6, 2019 · 2 comments

Comments

@franzliedke
Copy link
Collaborator

We encountered this in a test case, where we were using Restify for making requests to our Rails app. This app answered with HTTP 400 for certain invalid parameters. However, Rails sometimes sets the Content-Type header even for requests with empty bodies. This header makes Restify interpret the empty body as JSON, which then raises an exception.

Possible solutions:

  • Introduce a special case for empty response bodies, no matter the content type.
  • Handle any JSON parsing error and ignore the body - this might be a bit surprising, but it's a possible scenario that needs to be handled somehow. 😕

(Yes, the server is doing something wrong here, but more graceful error handling on the client side would probably be useful, too. At least I am not aware of a protocol for handling processing errors in Restify.)

@franzliedke
Copy link
Collaborator Author

Idea from @jgraichen: Ignore all errors when parsing relations, and throw when trying to access the parsed body data.

@franzliedke
Copy link
Collaborator Author

Same problem for the Msgpack processor.

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

No branches or pull requests

1 participant