Looking through the Angular 5+ guidance on making HTTP requests in Services we see the basic patterns appears as follows for a service:
getTasks(taskId: string): Observable<ITask[]> {
var url = this.baseServiceUrl + 'task/' + taskId;
this.fetchedTasks = this.http.get<ITask[]>(url);
return this.fetchedTasks;
}
A component may use it as follows
getTasks(taskId: string): void {
this.taskService.getTasks(taskId).subscribe(tasks => this.tasks = tasks);
}
Using the above case, how should this be modified to allow us to handle HTTP response codes such as 400, 403, 401, 404, and 5xx.
In short, we need the caller to be aware of faulted outcomes, vs, not found, etc. so they can handle related UI concerns
mapandcatch/catchErrorto return meaningful status/data back to the caller (component).