Angular 2 http service. Get detailed error information

后端 未结 3 2254
不知归路
不知归路 2021-01-04 10:30

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

3条回答
  •  攒了一身酷
    2021-01-04 11:04

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

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

    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...

    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.

提交回复
热议问题