Skip to content

Commit 2ec1b92

Browse files
author
Your Name
committed
RxJs Course
1 parent 81685c0 commit 2ec1b92

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

server/get-courses.route.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,24 @@ import {COURSES} from "./db-data";
77

88
export function getAllCourses(req: Request, res: Response) {
99

10-
/*
10+
1111
const error = (Math.random() >= 0.5);
1212

1313
if (error) {
1414
console.log("ERROR loading courses!");
1515
res.status(500).json({message: 'random error occurred.'});
1616
}
1717
else {
18-
*/
1918

2019
setTimeout(() => {
2120

22-
res.status(500).json({message: ' error occurred.'});
23-
24-
// res.status(200).json({payload:Object.values(COURSES)});
21+
res.status(200).json({payload:Object.values(COURSES)});
2522

2623
}, 200);
2724

2825

2926

30-
// }
27+
}
3128
}
3229

3330

src/app/home/home.component.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Component, OnInit} from '@angular/core';
22
import {Course} from "../model/course";
33
import {interval, noop, Observable, of, throwError, timer} from 'rxjs';
4-
import {catchError, delayWhen, finalize, map, retryWhen, shareReplay, tap} from 'rxjs/operators';
4+
import {catchError, delay, delayWhen, finalize, map, retryWhen, shareReplay, tap} from 'rxjs/operators';
55
import {createHttpObservable} from '../common/util';
66

77

@@ -22,21 +22,14 @@ export class HomeComponent implements OnInit {
2222

2323
const courses$: Observable<Course[]> = http$
2424
.pipe(
25-
catchError(err => {
26-
27-
console.log("Error occurred", err);
28-
29-
return throwError(err);
30-
31-
}),
32-
finalize(() => {
33-
34-
console.log('Finalize executed..');
35-
36-
}),
3725
tap(() => console.log("HTTP request executed")),
3826
map(res => Object.values(res["payload"]) ),
39-
shareReplay()
27+
shareReplay(),
28+
retryWhen(errors =>
29+
errors.pipe(
30+
delayWhen(() => timer(2000)
31+
)
32+
) )
4033
);
4134

4235
this.beginnerCourses$ = courses$

0 commit comments

Comments
 (0)