Skip to content

Commit cf16de0

Browse files
committed
fix: add catchError for http error
1 parent fbb5e82 commit cf16de0

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

apps/rxjs/38-catch-error/src/app/app.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { HttpClient } from '@angular/common/http';
33
import { Component, DestroyRef, OnInit, inject } from '@angular/core';
44
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
55
import { FormsModule } from '@angular/forms';
6-
import { Subject, concatMap, map } from 'rxjs';
6+
import { Subject, catchError, concatMap, map, of } from 'rxjs';
77

88
@Component({
99
imports: [CommonModule, FormsModule],
@@ -41,8 +41,11 @@ export class AppComponent implements OnInit {
4141
.pipe(
4242
map(() => this.input),
4343
concatMap((value) =>
44-
this.http.get(`https://jsonplaceholder.typicode.com/${value}/1`),
44+
this.http
45+
.get(`https://jsonplaceholder.typicode.com/${value}/1`)
46+
.pipe(catchError(() => of('Error occurred'))),
4547
),
48+
4649
takeUntilDestroyed(this.destroyRef),
4750
)
4851
.subscribe({

0 commit comments

Comments
 (0)