【发布时间】:2015-08-09 13:37:43
【问题描述】:
在下面的代码中,我想处理错误:
- 401:重定向到登录页面
- other : 显示错误信息(在错误信息中收到)
我没有找到正确的方法。
有什么想法吗?
谢谢,
模块.js
var app;
(function () {
app = angular.module("studentModule", []);
})()
Service.js
app.service('StudentService', function ($http) {
this.getAllStudent = function () {
return $http.get("http://myserver/api/Student/");
}
});
Controller.js
app.controller('studentController', function ($scope, StudentService) {
function GetAllRecords() {
var promiseGet = StudentService.getAllStudent();
promiseGet.then(function (pl) { $scope.Students = pl.data },
function (errorPl) {
$log.error('Some Error in Getting Records.', errorPl);
});
}
});
【问题讨论】:
-
你可以使用http拦截器并在常见的地方进行
-
是的,拦截器是必经之路。
标签: javascript angularjs asp.net-web-api error-handling