| 399 | * @publicApi |
| 400 | */ |
| 401 | export class HttpErrorResponse extends HttpResponseBase implements Error { |
| 402 | readonly name = 'HttpErrorResponse'; |
| 403 | readonly message: string; |
| 404 | readonly error: any | null; |
| 405 | |
| 406 | /** |
| 407 | * Errors are never okay, even when the status code is in the 2xx success range. |
| 408 | */ |
| 409 | override readonly ok = false; |
| 410 | |
| 411 | constructor(init: { |
| 412 | error?: any; |
| 413 | headers?: HttpHeaders; |
| 414 | status?: number; |
| 415 | statusText?: string; |
| 416 | url?: string; |
| 417 | redirected?: boolean; |
| 418 | responseType?: ResponseType; |
| 419 | }) { |
| 420 | // Initialize with a default status of 0 / Unknown Error. |
| 421 | super(init, 0, 'Unknown Error'); |
| 422 | |
| 423 | // If the response was successful, then this was a parse error. Otherwise, it was |
| 424 | // a protocol-level failure of some sort. Either the request failed in transit |
| 425 | // or the server returned an unsuccessful status code. |
| 426 | if (this.status >= 200 && this.status < 300) { |
| 427 | this.message = `Http failure during parsing for ${init.url || '(unknown url)'}`; |
| 428 | } else { |
| 429 | // TODO: Cleanup G3 to update the tests that rely on having the status text in the Error message. |
| 430 | this.message = `Http failure response for ${init.url || '(unknown url)'}: ${init.status} ${ |
| 431 | init.statusText |
| 432 | }`; |
| 433 | } |
| 434 | this.error = init.error || null; |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * We use these constant to prevent pulling the whole HttpStatusCode enum |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…