Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度拦截器-从500错误中获取消息_Javascript_Angularjs_Web Config_Interceptor - Fatal编程技术网

Javascript 角度拦截器-从500错误中获取消息

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) {

我使用的是角度拦截器,我想从500个错误(内部服务器错误)中获取消息

问题是,我在拦截器内部的responseError中得到了整个HTML

我读到我必须配置web.config,但我仍然得到整个HTML。我只是想得到这个信息

有可能吗

角度拦截器:

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}
    –使用转换函数转换的响应体
  • 状态–
    {number}
    –响应的HTTP状态代码
  • headers–
    {function([headerName])}
    –Header getter函数
  • config–
    {Object}
    –用于生成请求的配置对象
  • statusText–
    {string}
    –响应的HTTP状态文本

--

你从数据中得到了什么信息?什么都没有。因为在数据中,我有整个HTML,就像在第一张图片中一样。我做了一个编辑-看一看。