/ / Prístup k stavovému kódu HTTP pri úspešnej požiadavke na opakovanie - koffeescript, kódy stavu http, restangular

Prístup k stavovému kódu HTTP na úspešnú žiadosť o rešpektovanie - coffeescript, http-status-codes, restangular

Ako získam prístup k stavovému kódu odpovede HTTP po úspešnej žiadosti pomocou funkcie Restangular?

Príklad CoffeeScript

Restangular.all("orders").getList().then (result) ->
console.log result  # no status code
console.log "Preferably, status code should be here: ", result.status
, (error) ->
console.log "Error status code: ", error.status  # this works

Snažil som sa implementovať extraktor odpovede, aby sme ho mohli použiť ako metaúdaje, ale stavový kód je už odstránený v čase, keď prúdi do extraktora.

odpovede:

14 pre odpoveď č. 1

V konfigurácii modulov by ste použili setFullResponse na získanie stavového kódu pri úspešnej žiadosti.

https://github.com/mgonto/restangular#setfullresponse

var app = angular.module("app", ["restangular"]);

// Change setFullResponse to be true in the modules config.
app.config(["RestangularProvider", function (RestangularProvider) {
RestangularProvider.setFullResponse(true);
}]);

// Using the new response format.
app.controller("someController", ["Restangular", function (Restangular) {
Restangular.all("orders").getList().then(function (result) {
// Response from the server.
console.log(result.data);

// Response status code.
console.log(result.status);
});
}]);

Coffeescriptified:

app = angular.module("app", ["restangular"])

// Change setFullResponse to be true in the modules config.
app.config ["RestangularProvider", (RestangularProvider) ->
RestangularProvider.setFullResponse true
]

// Using the new response format.
app.controller "someController", ["Restangular", (Restangular) ->
Restangular.all("orders").getList().then (result) ->
// Response from the server.
console.log result.data

// Response status code.
console.log result.status
]

Dúfam, že to pomôže!