docs(docs-infra): fix handling of client-side errors in networking (#36608)

Previously example for handling client-side errors in networking didn't work when there was no Internet connection.
Caught error is ProgressEvent in such case, not ErrorEvent and error.error.message is undefined.

PR Close #36608
This commit is contained in:
Wojciech Okoński 2020-04-13 17:10:36 +02:00 committed by Misko Hevery
parent 36c7bebe40
commit ea89617880
2 changed files with 3 additions and 3 deletions

View File

@ -72,9 +72,9 @@ export class ConfigService {
// #docregion handleError
private handleError(error: HttpErrorResponse) {
if (error.error instanceof ErrorEvent) {
if (error.status === 0) {
// A client-side or network error occurred. Handle it accordingly.
console.error('An error occurred:', error.error.message);
console.error('An error occurred:', error.error);
} else {
// The backend returned an unsuccessful response code.
// The response body may contain clues as to what went wrong.

View File

@ -327,7 +327,7 @@ Two types of errors can occur.
* The server backend might reject the request, returning an HTTP response with a status code such as 404 or 500. These are error _responses_.
* 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 produce JavaScript `ErrorEvent` objects.
* 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.
`HttpClient` captures both kinds of errors in its `HttpErrorResponse`. You can inspect that response to identify the error's cause.