barker/bookie/src/app/core/error-logger.service.ts

37 lines
1.1 KiB
TypeScript
Raw Normal View History

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);
}
}