Joetjah
Joetjah

Reputation: 6132

303 response not redirected due to Javascript error

I'd like to fetch data from a webservice, which is done by:

$scope.data = itemsApi.search(null, $scope.filterCriteria);

The itemsApi is defined like this:

angular.module('rootApp')

.factory('itemsApi ', function($resource, rootURL) {
    return $resource(rootURL + '/items/:id/:action/:correlationUid', {
        id : '@itemIdentification'
    },

    search : {
        method : 'POST',
        isArray : false
    }
 });
});

Normally, this works fine. The data gets fetched and my Angular application finishes off the webpage by displaying the data.

However, I now have security measures in place which will redirect the user to a SSO login page if the user is not logged in or his session has expired. This means that it's possible to retrieve a 303 status code on the API call, and a webpage (html, 200) gets returned. The $scope.data now contains HTML instead of JSON because of the browser handling the redirect, and a Javascript error occurs, probably preventing the browser from continuing to follow the redirect:

"Error: [$resource:badcfg] Error in resource configuration. Expected response to contain an array but got an object http://errors.angularjs.org/1.2.32/$resource/badcfg?p0=array&p1=object ...

I've tried creating an Interceptor on the response, finding out if I retrieve HTML pages instead of JSON and act upon that, but I find it a dirty solution and I'm guessing it will give rise to problems when the project is in a further state.

How can I configure the application so redirects on http requests are followed instead of (attempting to) parsed to JSON?

Upvotes: 0

Views: 1041

Answers (0)

Related Questions