2023-02-02 00:17:04 +00:00
# HTTP client - Handle request errors
2022-10-07 00:06:43 +00:00
docs: Migrate pipe guide and its code examples to standalone (#51333)
**Pipes Sample Code**
Migrated all sample code in the `examples/pipes` folder. Did not touch the pipes in the ToH or Testing folders.
>The existing, complex discussion of the `CurrencyPipe` within `pipes-transform-data.md` cried out for a new `concurrency-formatting.component` example`.
**Extracted "pipe precedence" into its own page**
The topic had been extracted from `pipe.md` and tacked on to the bottom of the `pipes-overview.md` page.
It's an advanced and somewhat obscure topic that doesn't belong in the overview. Rather than throw it away, I created a new `pipe-precedence.md` page and added it to the bottom of the pipes section navigation.
I also tried to improve both the guide text and the companion component, `precedence.component`.
**How to create a pipe is missing**
The readers are told they can create their own pipes in several places throughout the docs. But there are no links and you can't navigate to a page that covers the topic. This is a serious omission!
The topic is introduced in the `pipes-custom-data-trans.md` page (extracted verbatim from `pipes.md`). But you can't navigate to this page and their are no links to it.
TODO: restore this page and add it to the left-nav.
**Change `pipes.md` references to `pipe-overview.md`**
The original, kitchen-sink page, `pipes.md`, was disconnected from navigation long ago, in favor of multiple pages such as `pipe-overview.md`. The page is still in the AIO documentation and can be found by searching or by links from 3rd party documenters. Landing on that page hides the left-nav.
In this commit, we treat `pipes.md` as deprecated (which it seems to be). Therefore, this commit retargets previous `pipes.md` references to `pipe-overview.md`.
>The `change-detection-slow-computations.md` is the exception. It refers to "pure pipes", a subject not covered in the current pipe documentation. That reference is retargeted to `api/core/Pipe#pure`.
Certain code files are only referenced in `pipe.md`. They still work and are displayed in the overall pipes code sample as before. Now they are marked with deprecation comments for future treatment or removal.
For consistency, certain sections of `pipes.md` were replaced by the contents of the corresponding current pages.
PR Close #51333
2023-08-10 06:34:27 +00:00
If the request fails on the server, `HttpClient` returns an _error_ object instead of a successful response.
2023-02-02 00:17:04 +00:00
The same service that performs your server transactions should also perform error inspection, interpretation, and resolution.
When an error occurs, you can obtain details of what failed to inform your user.
In some cases, you might also automatically [retry the request ](#retry ).
< a id = "error-details" > < / a >
## Getting error details
An app should give the user useful feedback when data access fails.
A raw error object is not particularly useful as feedback.
In addition to detecting that an error has occurred, you need to get error details and use those details to compose a user-friendly response.
Two types of errors can occur.
docs: Migrate pipe guide and its code examples to standalone (#51333)
**Pipes Sample Code**
Migrated all sample code in the `examples/pipes` folder. Did not touch the pipes in the ToH or Testing folders.
>The existing, complex discussion of the `CurrencyPipe` within `pipes-transform-data.md` cried out for a new `concurrency-formatting.component` example`.
**Extracted "pipe precedence" into its own page**
The topic had been extracted from `pipe.md` and tacked on to the bottom of the `pipes-overview.md` page.
It's an advanced and somewhat obscure topic that doesn't belong in the overview. Rather than throw it away, I created a new `pipe-precedence.md` page and added it to the bottom of the pipes section navigation.
I also tried to improve both the guide text and the companion component, `precedence.component`.
**How to create a pipe is missing**
The readers are told they can create their own pipes in several places throughout the docs. But there are no links and you can't navigate to a page that covers the topic. This is a serious omission!
The topic is introduced in the `pipes-custom-data-trans.md` page (extracted verbatim from `pipes.md`). But you can't navigate to this page and their are no links to it.
TODO: restore this page and add it to the left-nav.
**Change `pipes.md` references to `pipe-overview.md`**
The original, kitchen-sink page, `pipes.md`, was disconnected from navigation long ago, in favor of multiple pages such as `pipe-overview.md`. The page is still in the AIO documentation and can be found by searching or by links from 3rd party documenters. Landing on that page hides the left-nav.
In this commit, we treat `pipes.md` as deprecated (which it seems to be). Therefore, this commit retargets previous `pipes.md` references to `pipe-overview.md`.
>The `change-detection-slow-computations.md` is the exception. It refers to "pure pipes", a subject not covered in the current pipe documentation. That reference is retargeted to `api/core/Pipe#pure`.
Certain code files are only referenced in `pipe.md`. They still work and are displayed in the overall pipes code sample as before. Now they are marked with deprecation comments for future treatment or removal.
For consistency, certain sections of `pipes.md` were replaced by the contents of the corresponding current pages.
PR Close #51333
2023-08-10 06:34:27 +00:00
- The server backend might reject the request, returning an HTTP response with a status code such as 404 or 500.
These are error _responses_ .
2023-02-02 00:17:04 +00:00
docs: Migrate pipe guide and its code examples to standalone (#51333)
**Pipes Sample Code**
Migrated all sample code in the `examples/pipes` folder. Did not touch the pipes in the ToH or Testing folders.
>The existing, complex discussion of the `CurrencyPipe` within `pipes-transform-data.md` cried out for a new `concurrency-formatting.component` example`.
**Extracted "pipe precedence" into its own page**
The topic had been extracted from `pipe.md` and tacked on to the bottom of the `pipes-overview.md` page.
It's an advanced and somewhat obscure topic that doesn't belong in the overview. Rather than throw it away, I created a new `pipe-precedence.md` page and added it to the bottom of the pipes section navigation.
I also tried to improve both the guide text and the companion component, `precedence.component`.
**How to create a pipe is missing**
The readers are told they can create their own pipes in several places throughout the docs. But there are no links and you can't navigate to a page that covers the topic. This is a serious omission!
The topic is introduced in the `pipes-custom-data-trans.md` page (extracted verbatim from `pipes.md`). But you can't navigate to this page and their are no links to it.
TODO: restore this page and add it to the left-nav.
**Change `pipes.md` references to `pipe-overview.md`**
The original, kitchen-sink page, `pipes.md`, was disconnected from navigation long ago, in favor of multiple pages such as `pipe-overview.md`. The page is still in the AIO documentation and can be found by searching or by links from 3rd party documenters. Landing on that page hides the left-nav.
In this commit, we treat `pipes.md` as deprecated (which it seems to be). Therefore, this commit retargets previous `pipes.md` references to `pipe-overview.md`.
>The `change-detection-slow-computations.md` is the exception. It refers to "pure pipes", a subject not covered in the current pipe documentation. That reference is retargeted to `api/core/Pipe#pure`.
Certain code files are only referenced in `pipe.md`. They still work and are displayed in the overall pipes code sample as before. Now they are marked with deprecation comments for future treatment or removal.
For consistency, certain sections of `pipes.md` were replaced by the contents of the corresponding current pages.
PR Close #51333
2023-08-10 06:34:27 +00:00
- Something could go wrong on the client-side such as a network error that prevents the request from completing successfully or an exception thrown in an RxJS operator.
These errors have `status` set to `0` and the `error` property contains a `ProgressEvent` object, whose `type` might provide further information.
2023-02-02 00:17:04 +00:00
`HttpClient` captures both kinds of errors in its `HttpErrorResponse` .
Inspect that response to identify the error's cause.
The following example defines an error handler in the previously defined ConfigService.
< code-example header = "app/config/config.service.ts (handleError)" path = "http/src/app/config/config.service.ts" region = "handleError" > < / code-example >
The handler returns an RxJS `ErrorObservable` with a user-friendly error message.
2023-09-21 17:10:16 +00:00
The following code updates the `getConfig()` method, using a [pipe ](guide/rx-library#operators 'RxJS Operators' ) to send all observables returned by the `HttpClient.get()` call to the error handler.
2023-02-02 00:17:04 +00:00
< code-example header = "app/config/config.service.ts (getConfig v.3 with error handler)" path = "http/src/app/config/config.service.ts" region = "getConfig_3" > < / code-example >
< a id = "retry" > < / a >
## Retrying a failed request
Sometimes the error is transient and goes away automatically if you try again.
For example, network interruptions are common in mobile scenarios, and trying again can produce a successful result.
docs: Migrate pipe guide and its code examples to standalone (#51333)
**Pipes Sample Code**
Migrated all sample code in the `examples/pipes` folder. Did not touch the pipes in the ToH or Testing folders.
>The existing, complex discussion of the `CurrencyPipe` within `pipes-transform-data.md` cried out for a new `concurrency-formatting.component` example`.
**Extracted "pipe precedence" into its own page**
The topic had been extracted from `pipe.md` and tacked on to the bottom of the `pipes-overview.md` page.
It's an advanced and somewhat obscure topic that doesn't belong in the overview. Rather than throw it away, I created a new `pipe-precedence.md` page and added it to the bottom of the pipes section navigation.
I also tried to improve both the guide text and the companion component, `precedence.component`.
**How to create a pipe is missing**
The readers are told they can create their own pipes in several places throughout the docs. But there are no links and you can't navigate to a page that covers the topic. This is a serious omission!
The topic is introduced in the `pipes-custom-data-trans.md` page (extracted verbatim from `pipes.md`). But you can't navigate to this page and their are no links to it.
TODO: restore this page and add it to the left-nav.
**Change `pipes.md` references to `pipe-overview.md`**
The original, kitchen-sink page, `pipes.md`, was disconnected from navigation long ago, in favor of multiple pages such as `pipe-overview.md`. The page is still in the AIO documentation and can be found by searching or by links from 3rd party documenters. Landing on that page hides the left-nav.
In this commit, we treat `pipes.md` as deprecated (which it seems to be). Therefore, this commit retargets previous `pipes.md` references to `pipe-overview.md`.
>The `change-detection-slow-computations.md` is the exception. It refers to "pure pipes", a subject not covered in the current pipe documentation. That reference is retargeted to `api/core/Pipe#pure`.
Certain code files are only referenced in `pipe.md`. They still work and are displayed in the overall pipes code sample as before. Now they are marked with deprecation comments for future treatment or removal.
For consistency, certain sections of `pipes.md` were replaced by the contents of the corresponding current pages.
PR Close #51333
2023-08-10 06:34:27 +00:00
The [RxJS library ](guide/rx-library ) offers several _retry_ operators.
2023-02-02 00:17:04 +00:00
For example, the `retry()` operator automatically re-subscribes to a failed `Observable` a specified number of times.
docs: Migrate pipe guide and its code examples to standalone (#51333)
**Pipes Sample Code**
Migrated all sample code in the `examples/pipes` folder. Did not touch the pipes in the ToH or Testing folders.
>The existing, complex discussion of the `CurrencyPipe` within `pipes-transform-data.md` cried out for a new `concurrency-formatting.component` example`.
**Extracted "pipe precedence" into its own page**
The topic had been extracted from `pipe.md` and tacked on to the bottom of the `pipes-overview.md` page.
It's an advanced and somewhat obscure topic that doesn't belong in the overview. Rather than throw it away, I created a new `pipe-precedence.md` page and added it to the bottom of the pipes section navigation.
I also tried to improve both the guide text and the companion component, `precedence.component`.
**How to create a pipe is missing**
The readers are told they can create their own pipes in several places throughout the docs. But there are no links and you can't navigate to a page that covers the topic. This is a serious omission!
The topic is introduced in the `pipes-custom-data-trans.md` page (extracted verbatim from `pipes.md`). But you can't navigate to this page and their are no links to it.
TODO: restore this page and add it to the left-nav.
**Change `pipes.md` references to `pipe-overview.md`**
The original, kitchen-sink page, `pipes.md`, was disconnected from navigation long ago, in favor of multiple pages such as `pipe-overview.md`. The page is still in the AIO documentation and can be found by searching or by links from 3rd party documenters. Landing on that page hides the left-nav.
In this commit, we treat `pipes.md` as deprecated (which it seems to be). Therefore, this commit retargets previous `pipes.md` references to `pipe-overview.md`.
>The `change-detection-slow-computations.md` is the exception. It refers to "pure pipes", a subject not covered in the current pipe documentation. That reference is retargeted to `api/core/Pipe#pure`.
Certain code files are only referenced in `pipe.md`. They still work and are displayed in the overall pipes code sample as before. Now they are marked with deprecation comments for future treatment or removal.
For consistency, certain sections of `pipes.md` were replaced by the contents of the corresponding current pages.
PR Close #51333
2023-08-10 06:34:27 +00:00
_Re-subscribing_ to the result of an `HttpClient` method call has the effect of reissuing the HTTP request.
2023-02-02 00:17:04 +00:00
The following example shows how to pipe a failed request to the `retry()` operator before passing it to the error handler.
< code-example header = "app/config/config.service.ts (getConfig with retry)" path = "http/src/app/config/config.service.ts" region = "getConfig" > < / code-example >
2023-08-17 05:11:14 +00:00
@reviewed 2023-08-29