Unexpected token u in Restangular Error Interceptor


I’m using Restangular interceptor to handle errors with status code as 412,409 etc.
But I’m not getting status in the requestInterceptor function.
I have declared the Restangular RequestInterceptor using Typescript.

In my app.ts file,

   Restangular.setErrorInterceptor(function(response) {//code to handle error});

enter image description here


Restangular provides an option to access a full response access, probably setting up this might help. By using Restangular.setFullResponse(true) you should be able to access the status code in your interceptor.

So, I guess according to your snippet now it could look like this(since there is where you are injecting Restangular if you have any other configuration section that where the setting should go)

   Restangular.setErrorInterceptor(function(response) {//code to handle error});

It’s important to point out that setting up this option, now the access to your responses will be sightly different for all your services unless you create something to handle the next .data behavior:

 var result = response.data;
 var statusCode = result.status;
 var responseData = result.myApiResponse;

For more information please check: https://github.com/mgonto/restangular#setfullresponse, and hope my post helps.

Answered By – Jose R.

Answer Checked By – David Goodson (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.