Skip to content

Handling invalid JSON bodies #31

@franzliedke

Description

@franzliedke

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions