填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

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.

构造函数

      
      constructor(init: { error?: any; headers?: HttpHeaders; status?: number; statusText?: string; url?: string; })
    
参数
init object

属性

属性说明
name: 'HttpErrorResponse'只读
message: string只读
error: any | null只读
ok: false只读

只要是错误,其 ok 就永远为 false,就算其 HTTP 状态码是 2xx 也一样。

Errors are never okay, even when the status code is in the 2xx success range.