2

Angularjs v. 1.2.0rc3 with phonegap 3.1 and django-rest-framework

When posting data to my API (login form) I am getting status 200 in angularjs no matter if I authenticate with proper credentials etc. Even though I simply return HTTP_400 in the API view as in the example below, angularjs thinks this is a HTTP_200 status code. I am sure the backend API returns HTTP_400 which works fine when using local http server. I can also confirm this by debugging the api view.

Here's the example code. Django Rest Framework code:

class LoginView(APIView):
    def post(self, request):
        return Response({}, status=status.HTTP_400_BAD_REQUEST)

and my angularjs controller:

$scope.login = function () {
    $http.post(API_URL, $scope.loginUser).then(
        function(response) {
            console.log('STATUS : ' + response.status);
            console.log('request OK');
        },
        function() {
            console.log('request is NOT OK');
        )};

As far as I know phonegap uses a local file:// protocol so there should be no CORS related problem ?

When the same on chrome browser, I get Origin file:// is not allowed by Access-Control-Allow-Origin. Adding --disable-web-security flag to chrome startup script eliminates this problem but it does not solve the "always 200 status code" for phonegap.

Testing on android 2.3 & phonegap 3.1 & angularjs 1.2.0rc3

5
  • Seems like this is an angularjs problem: github.com/angular/angular.js/issues/4436 Commented Oct 30, 2013 at 19:55
  • I am having the same issue using angular 1.2.0rc3 and phonegap 3.1. Even though the server returns status code 401 in my interceptor it still shows up as status 200. Same issue persists in 1.2 stable also. Commented Nov 9, 2013 at 14:33
  • By the way I did not have this problem with angular 1.2.0rc2, so could you please try that and report back. Commented Nov 9, 2013 at 14:34
  • Too bad this patch which potentially fixes the issue wasn't merged before stable release. Commented Nov 9, 2013 at 14:38
  • same issue for me. It doesnt capture 401, 404 status codes of error callback, but it works on webserver serving files to browser Commented Jan 23, 2014 at 14:05

2 Answers 2

1

Confirmed fixed in AngularJS 1.2.3

See the line here: https://github.com/angular/angular.js/blob/v1.2.3/src/ng/httpBackend.js#L122

Sign up to request clarification or add additional context in comments.

2 Comments

Consider an Up-Vote for sharing the actual line of code :D
Confirmed. Upgraded from 1.2.1 to 1.2.3 and the problems was indeed resolved.
0

Upgrade to Latest(version 1.2.9) AngularJS version, Its resolved now.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.