Skip to content

Commit e0d21d4

Browse files
committed
error handling
1 parent da827d8 commit e0d21d4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/app/places/available-places/available-places.component.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Component, DestroyRef, inject, OnInit, signal } from '@angular/core';
22
import { HttpClient } from '@angular/common/http';
33

4-
import { map, tap } from 'rxjs/operators';
4+
import { catchError, map, tap } from 'rxjs/operators';
5+
import { throwError } from 'rxjs';
56

67
import { Place } from '../../models/place.model';
78
import { PlacesComponent } from '../places.component';
@@ -33,6 +34,10 @@ export class AvailablePlacesComponent implements OnInit {
3334
console.log('Raw Response: ', rawResp);
3435
}),
3536
map(data => data.body),
37+
catchError(error => {
38+
console.error(error);
39+
return throwError(() => new Error('Something went wrong!'));
40+
}),
3641
)
3742
.subscribe({
3843
next: resp => {
@@ -41,6 +46,9 @@ export class AvailablePlacesComponent implements OnInit {
4146
complete: () => {
4247
this.isFetching.set(false);
4348
},
49+
error: (err: Error) => {
50+
console.error(err.message);
51+
},
4452
});
4553

4654
this.destroyRef.onDestroy(() => availablePlaceSub.unsubscribe());

0 commit comments

Comments
 (0)