Initial commit for the Angular part. We are nowhere yet.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {throwError} from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ErrorLoggerService {
|
||||
constructor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Http operation that failed.
|
||||
* Let the app continue.
|
||||
* @param operation - name of the operation that failed
|
||||
* @param result - optional value to return as the observable result
|
||||
*/
|
||||
public handleError<T>(serviceName = 'error-logger', operation = 'operation', result?: T) {
|
||||
return (error: any): Observable<T> => {
|
||||
|
||||
// TODO: send the error to remote logging infrastructure
|
||||
console.error(error); // log to console instead
|
||||
|
||||
// TODO: better job of transforming error for user consumption
|
||||
this.log(serviceName, `${operation} failed: ${error.message}`);
|
||||
|
||||
// // Let the app keep running by returning an empty result.
|
||||
// return of(result as T);
|
||||
return throwError(error);
|
||||
};
|
||||
}
|
||||
|
||||
public log(serviceName = 'error-logger', message: string) {
|
||||
console.log(serviceName + 'Service: ' + message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user