You can use the promiss callbacks then
, catch
and finally
after the $resource
call.
For example. If you want to catch an error after a call, you would do something like this:
RestAPI.save({resource}, {data}, callbackFunction).$promise.catch(function(response) {
//this will be fired upon error
if(response.status == 500) alert('Something baaad happend');
}).then(function() {
//this will be fired upon success
});
The response
object will have status
and the statusText
properties. status
being an integer status code and statusText
the text. You'll also have the data
property containing the server response.
edit: as suggested, it was response.status
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…