mirror of
https://github.com/richard-loafle/fuse-angular.git
synced 2024-10-30 01:08:47 +00:00
(apps/academy) Better error handling on courses that are not exist
This commit is contained in:
parent
284e282761
commit
deeef323f9
|
@ -75,7 +75,10 @@ export class AcademyMockApi
|
||||||
|
|
||||||
// Find the course and attach steps to it
|
// Find the course and attach steps to it
|
||||||
const course = courses.find((item) => item.id === id);
|
const course = courses.find((item) => item.id === id);
|
||||||
|
if ( course )
|
||||||
|
{
|
||||||
course.steps = steps;
|
course.steps = steps;
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
200,
|
200,
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { BehaviorSubject, Observable } from 'rxjs';
|
import { BehaviorSubject, Observable, of, throwError } from 'rxjs';
|
||||||
import { tap } from 'rxjs/operators';
|
import { map, switchMap, tap } from 'rxjs/operators';
|
||||||
import { Category, Course } from 'app/modules/admin/apps/academy/academy.types';
|
import { Category, Course } from 'app/modules/admin/apps/academy/academy.types';
|
||||||
|
import { Chat } from 'app/modules/admin/apps/chat/chat.types';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
|
@ -83,8 +84,22 @@ export class AcademyService
|
||||||
getCourseById(id: string): Observable<Course>
|
getCourseById(id: string): Observable<Course>
|
||||||
{
|
{
|
||||||
return this._httpClient.get<Course>('api/apps/academy/courses/course', {params: {id}}).pipe(
|
return this._httpClient.get<Course>('api/apps/academy/courses/course', {params: {id}}).pipe(
|
||||||
tap((response: any) => {
|
map((course) => {
|
||||||
this._course.next(response);
|
|
||||||
|
// Update the course
|
||||||
|
this._course.next(course);
|
||||||
|
|
||||||
|
// Return the course
|
||||||
|
return course;
|
||||||
|
}),
|
||||||
|
switchMap((course) => {
|
||||||
|
|
||||||
|
if ( !course )
|
||||||
|
{
|
||||||
|
return throwError('Could not found course with id of ' + id + '!');
|
||||||
|
}
|
||||||
|
|
||||||
|
return of(course);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user