Javascript 角度拦截器-从500错误中获取消息
我使用的是角度拦截器,我想从500个错误(内部服务器错误)中获取消息 问题是,我在拦截器内部的responseError中得到了整个HTML 我读到我必须配置web.config,但我仍然得到整个HTML。我只是想得到这个信息 有可能吗 角度拦截器:Javascript 角度拦截器-从500错误中获取消息,javascript,angularjs,web-config,interceptor,Javascript,Angularjs,Web Config,Interceptor,我使用的是角度拦截器,我想从500个错误(内部服务器错误)中获取消息 问题是,我在拦截器内部的responseError中得到了整个HTML 我读到我必须配置web.config,但我仍然得到整个HTML。我只是想得到这个信息 有可能吗 角度拦截器: app.config(['$httpProvider', function ($httpProvider) { $httpProvider.interceptors.push(function ($q, $rootScope) {
app.config(['$httpProvider', function ($httpProvider) {
$httpProvider.interceptors.push(function ($q, $rootScope) {
return {
request: function (config) {
//the same config / modified config / a new config needs to be returned.
return config;
},
requestError: function (rejection) {
//Initializing error list
if ($rootScope.errorList == undefined) {
$rootScope.errorList = [];
}
$rootScope.errorList.push(rejection.data);
//It has to return the rejection, simple reject call doesn't work
return $q.reject(rejection);
},
response: function (response) {
//the same response/modified/or a new one need to be returned.
return response;
},
responseError: function (rejection) {
//Initializing the error list
if ($rootScope.errorList == undefined) {
$rootScope.errorList = [];
}
//Adding to error list
$rootScope.errorList.push(rejection.data);
//It has to return the rejection, simple reject call doesn't work
return $q.reject(rejection);
}
};
});
}]);
Web.Config
<system.webServer>
<httpErrors existingResponse="PassThrough" errorMode="Detailed"></httpErrors>
</system.webServer>
编辑:
我想从异常快照中获取消息
我想从500个错误(内部服务器错误)中获取消息
使用response.statusText
获取消息:
responseError: function (errorResponse) {
//Initializing the error list
if ($rootScope.errorList == undefined) {
$rootScope.errorList = [];
}
//Adding to error list
$rootScope.errorList.push(errorResponse.statusText);
//It has to return the rejection, simple reject call doesn't work
return $q.reject(errorResponse);
}
从文档中:
响应对象具有以下属性:
- 数据–
–使用转换函数转换的响应体{string | Object}
- 状态–
–响应的HTTP状态代码{number}
- headers–
–Header getter函数{function([headerName])}
- config–
–用于生成请求的配置对象{Object}
- statusText–
–响应的HTTP状态文本{string}
--你从数据中得到了什么信息?什么都没有。因为在数据中,我有整个HTML,就像在第一张图片中一样。我做了一个编辑-看一看。