HttpErrorResponse
一个用于表示错误或失败的响应对象,或者来自执行请求时发生的错误给出的失败的 HTTP 状态码,或者来自在解析响应对象期间发生的其它错误。
A response that represents an error or failure, either from a non-successful HTTP status, an error while executing the request, or some other failure which occurred during the parsing of the response.
class HttpErrorResponse extends HttpResponseBase implements Error {
constructor(init: { error?: any; headers?: HttpHeaders; status?: number; statusText?: string; url?: string; })
name: 'HttpErrorResponse'
message: string
error: any | null
ok: false
// 继承自 common/http/HttpResponseBase
constructor(init: { headers?: HttpHeaders; status?: number; statusText?: string; url?: string; }, defaultStatus: number = HttpStatusCode.Ok, defaultStatusText: string = 'OK')
headers: HttpHeaders
status: number
statusText: string
url: string | null
ok: boolean
type: HttpEventType.Response | HttpEventType.ResponseHeader
}
说明
任何从 Observable
响应流中返回的错误都会被包装成 HttpErrorResponse
对象,以便在发生错误时,提供关于 HTTP 层状态的额外上下文信息。 该错误或者包含一个包装好的错误对象,或者包含一个从服务端返回的错误响应体。
Any error returned on the Observable
response stream will be wrapped in an HttpErrorResponse
to provide additional context about the state of the HTTP layer when the error occurred. The error property will contain either a wrapped Error object or the error response returned from the server.
构造函数
参数
|
属性
属性 | 说明 |
---|---|
name: 'HttpErrorResponse' | 只读 |
message: string | 只读 |
error: any | null | 只读 |
ok: false | 只读 只要是错误,其 Errors are never okay, even when the status code is in the 2xx success range. |