Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Error handling not supporting all Accept headers (throwing parse error) #9148

Closed
kmturley opened this issue Sep 18, 2014 · 6 comments
Closed

Comments

@kmturley
Copy link

When I send a request with a resource:
Request Method: POST
Accept: application/json, text/plain, /

I get a response from the server with:
Status Code: 403
Content-Type: text/plain

Angular resource is erroring as it is trying to convert the plain/text response into json, which throws a parse error. This also means my resource error callback has the parse object error, not the original request error (with status code).

Workarounds to this bug:

  • add support application/json error responses on the server
  • override the accepts header so the browser ignores other responses, then angular doesn't error:
    $http.defaults.headers.common.Accept = "application/json";

Actual fix would be:

  • angular needs to handle error responses with all the content types specified in the accepts header, without parse errors
@caitp
Copy link
Contributor

caitp commented Sep 18, 2014

Related (Possibly duplicate, but we usually don't care about the Accept header re: this issue): #5756, #2973, #5765

@caitp caitp added this to the 1.3.0 milestone Sep 18, 2014
@IgorMinar IgorMinar modified the milestones: Backlog, 1.3.0 Oct 7, 2014
@IgorMinar
Copy link
Contributor

We are not going to fix this in 1.3 since the issue only occurs with error pages that return response that looks like JSON (starts with { and ends with }). Our autodetection is lame, but we fixed all the other common scenarios when it was problematic and this is the only one that remains.

In the future version we are going to fully honor the headers and not use autodetection, so that will resolve even this problem.

@pkozlowski-opensource
Copy link
Member

@kmturley out of curiosity - what is the response body from your server in case of error? A number of fixes landed in master recently that don't try to parse blank responses as JSON.

@kmturley
Copy link
Author

@pkozlowski-opensource I don't have the error response body to hand any more. However from memory I think the response body was empty, or had a small string in it

@pkozlowski-opensource
Copy link
Member

@kmturley so I think that this particular issue is fixed in master already. Would be cool if you could try with https://code.angularjs.org/snapshot/angular.js

@pkozlowski-opensource
Copy link
Member

We haven't heard from @kmturley but I believe that the issue is fixed now. Basically there were 2 separate issues discussed here:

  • errors when trying to JSON-parse an empty / blank request - this is already fixed in master
  • JSON-like responses being interpreted incorrectly as JSON - most common issues were addressed and the recent removal of the default transforms from the $templateRequest eliminates the problem for templates. I guess we don't want to push it any further in 1.x

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants