You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
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
The text was updated successfully, but these errors were encountered:
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.
@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.
@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
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
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:
$http.defaults.headers.common.Accept = "application/json";
Actual fix would be:
The text was updated successfully, but these errors were encountered: