Angular 2 http服务。获取详细的错误信息 [英] Angular 2 http service. Get detailed error information

查看:157
本文介绍了Angular 2 http服务。获取详细的错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行Angular2对离线服务器的http调用并没有提供太多的信息,它的错误响应对象我在Observable的.catch(错误)操作符或订阅错误代理(他们都共享相同的信息实际上)。但是正如您在控制台的屏幕截图中所看到的那样,zone.js以某种方式显示实际的错误。
那么,如何获取这个具体的错误信息(net :: ERR_CONNECTION_REFUSED)?

Executing Angular2 http call to the offline server doesn't provide much info in it's "error response" object I'm getting in the Observable's .catch(error) operator or subscription error delegate (they are both share the same info actually). But as you can see on the screen shot of the console there's actual error was displayed by zone.js somehow. So, how can I get this specific error info (net::ERR_CONNECTION_REFUSED)?

谢谢。

推荐答案

每当服务器没有响应时,response.status将始终等于0(零)

Whenever server do not respond, response.status will be always equal to 0 (zero)

{
  type: 3, //ResponseType.Error
  status: 0, // problem connecting endpoint
}

另请注意,当您执行CORS请求时,但来源(浏览器中的网址)未获授权(不在允许在远程端点中配置的主机名列表)响应将类似于上述,除了类型属性例外,将等于4 = ResponseType.Opaque ...

Also note, when you are performing CORS request, but origin (url in browser) is not authorized (not in allowed list of host names configured in remote endpoint) the response would be similar to above, with exception to type attribute which will be equal to 4 = ResponseType.Opaque...

这意味着连接是做出的,但是例如,返回的OPTIONS请求不包含源或HTTPS请求的头文件从HTTP来源执行。

This means, connection was made, but for instance, OPTIONS request returned with headers which do not contain origin or HTTPS request was performed from HTTP origin.

这篇关于Angular 2 http服务。获取详细的错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆