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. :confused:
(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.)
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 theContent-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:
(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.)