Getting status -1 instead of 401 Angularjs

I am trying to get a response from the server. The function looks like this:

function getOverview() {
        var req = {
            method: 'GET',
            url: base,
            headers: {
                'authorization': 'Bearer ' + GottenTokens.getSessionToken()
            }
        };

        return $http(req).then(
            function successCallback(response) {
                return response;
            }, function errorCallback(response) {
                console.log(response);
                return response;
            });
    }

When the state is 200, there are no problems, it returns a good response with a status of 200. But ... when the status is 401, it returns a response with a status of -1:

Object {data: null, status: -1, config: Object, statusText: ""}

I tried this in the postman, and I saw the status 401 there, and also in the browser it says this:

XMLHttpRequest cannot load http://localhost:5000/overview. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 401.

This means that the browser and the postman accept the status from the server, but it does not come in Angularjs. I tried this post: Capture Http 401 , but it does not help me. I have this function in the "factory".

By the way, the server is written in akka. I don’t know if he has something to do. It used to be in NodeJS, and I had no problems. Since this is in akka, I cannot get status in Angularjs.

Can someone help me?

+4
1

- CORS. , , 401.

, "Access-Control-Allow-Origin" 401, , .

+2

All Articles