2020-10-11 05:26:29 +00:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { throwError } from 'rxjs';
|
|
|
|
import { Observable } from 'rxjs/internal/Observable';
|
2019-06-13 19:02:34 +00:00
|
|
|
|
|
|
|
@Injectable({
|
2020-10-11 05:26:29 +00:00
|
|
|
providedIn: 'root',
|
2019-06-13 19:02:34 +00:00
|
|
|
})
|
|
|
|
export class ErrorLoggerService {
|
2020-10-11 05:26:29 +00:00
|
|
|
public static log(serviceName = 'error-logger', message: string) {
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log(`${serviceName}Service: ${message}`);
|
2019-06-13 19:02:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2020-10-11 05:26:29 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars, class-methods-use-this
|
2019-06-13 19:02:34 +00:00
|
|
|
public handleError<T>(serviceName = 'error-logger', operation = 'operation', result?: T) {
|
|
|
|
return (error: any): Observable<T> => {
|
2020-10-11 05:26:29 +00:00
|
|
|
ErrorLoggerService.log(serviceName, `${operation} failed: ${error}`);
|
2019-06-13 19:02:34 +00:00
|
|
|
return throwError(error);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|