-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Exception thrown for empty 204 HTTP response #9532
Comments
Oh, I should mention that the HTTP response was serialized by Jersey (https://jersey.java.net/). Its fairly popular in the Java community so I'm guessing others will hit this once they upgrade AngularJS. |
Empty string isn't really valid JSON, is it? In any case we could test that the string it's non-empty before parsing? |
Here is the bug on Jersey that talks about this: The crux of the argument seems to be this part:
I believe testing for an empty string would work but my read of this is that the status code should be looked at instead since its more explicit. |
Rfc2616 is entirely unrelated to JSON---basically we shouldn't have a content-type with application/json if the text is empty. However, we do need to deal with this for HEAD requests at the very least |
This will be fixed by #9529 |
When a response contains an `application/json` header and the response is empty the response should be left as is. Fixes angular#9532
Awesome - thanks for the quick fix! I'll pick this up in the next RC. |
I just upgraded to AngularJS 1.3.0-rc5 and I'm seeing an exception when $http attempts to handle a REST call response which returns a 204 status code with an empty entity (basically an empty string):
It looks like the response handling logic was changed so that setting a content type of "application/json" now properly attempts to parse the response as JSON every time. However, if the response is empty the JSON.parse() call fails. I wonder if perhaps a return code of 204 might need some special handling which interprets the returned data as undefined or null and does not attempt to parse the response entity.
The text was updated successfully, but these errors were encountered: