restangular
restangular copied to clipboard
response header visible in network tab in chrome debug but not in restangular response.
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)
Also the response in this case is also blank
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
..
Is there a way to get header value: X-Mob-Error-Code in my js
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
thanks stamy for responding .. but that will need a change in the rest service . Isn't there another way ?
@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
You should be able to get the headers like this:
RestangularProvider.addResponseInterceptor(function(data, operation, what, url, response, deferred) {
console.log(response.headers())
})