Tuesday 11 April 2017

How to get status code in angular 1.5.6?

I have a service with getData method

var getData = () => {
    return $http({
        method: 'GET',
        url: 'myURL',
        headers: {
            'Authorization': 'token'
        }
    });
};

I'm trying to use it with bellow code

dataservice.getData().then(response => {
                    console.log(response)
                })
                .catch((err) => {
                    console.log(err));
                })

And for good request (when I'm autorized) it works fine, I get my data, but then token is not valid I'm gettin error whitout status code

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

My goal is to get status code 401 'not autorized'



via nightmare

No comments:

Post a Comment