restangular icon indicating copy to clipboard operation
restangular copied to clipboard

response header visible in network tab in chrome debug but not in restangular response.

Open rishisignin opened this issue 9 years ago • 4 comments

I am using restangular as: Restangular.all('config/approveDynamic/'+serviceCode).getList({cluster:cluster}).then(function(result) { //success code },function(errorResult){ //error code }); I want to show a header value in error code area. The value is visible in network tab in chrome debug(X-Mob-Error-Code) capture1 Also the response in this case is also blank capture2

I tried this in my js: RestangularProvider.setResponseInterceptor(function (data, operation, what, url, response, deferred) { alert(JSON.stringify(response)); return data; });

RestangularProvider.setErrorInterceptor(function(response, deferred, responseHandler) {
    alert(JSON.stringify(response));
    return data;
});

I am sending the alert window screenshot capture3 ..

Is there a way to get header value: X-Mob-Error-Code in my js

rishisignin avatar May 15 '15 07:05 rishisignin

I am not sure, but I think the server with response should include this header Access-Control-Allow-Headers and it should contain the value X-Mob-Error-Code. So it would look like: Access-Control-Allow-Headers: X-Mob-Error-Code

sarunast avatar May 15 '15 13:05 sarunast

thanks stamy for responding .. but that will need a change in the rest service . Isn't there another way ?

rishisignin avatar May 15 '15 17:05 rishisignin

@rishisignin did you ever resolve this? I don't have direct access to set the REST web service headers, and it seems very strange that the network tab shows them (confirmed) but Restangular doesn't even with setFullResponse set as true

chorsnell avatar Aug 16 '16 10:08 chorsnell

You should be able to get the headers like this:

RestangularProvider.addResponseInterceptor(function(data, operation, what, url, response, deferred) {
  console.log(response.headers())
})

daviesgeek avatar Aug 31 '16 03:08 daviesgeek