更新时间:2022-05-04 05:18:26
你可以使用promiss回调then
、catch
和finally
after$resource
调用.
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
});
response
对象将具有 status
和 statusText
属性.status
是一个整数状态代码,statusText
是文本.您还将拥有包含服务器响应的 data
属性.
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.
按照建议,它是 response.status