src/app/_interceptors/logging.interceptor.ts
Methods |
constructor(loggingService: LoggingService)
|
||||||
Parameters :
|
intercept | |||||||||
intercept(request: HttpRequest
|
|||||||||
Parameters :
Returns :
Observable<HttpEvent<unknown>>
|
import { Injectable } from '@angular/core';
import {
HttpRequest,
HttpHandler,
HttpEvent,
HttpInterceptor,
HttpResponse,
} from '@angular/common/http';
import { Observable } from 'rxjs';
import { LoggingService } from '@app/_services/logging.service';
import { finalize, tap } from 'rxjs/operators';
@Injectable()
export class LoggingInterceptor implements HttpInterceptor {
constructor(private loggingService: LoggingService) {}
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
return next.handle(request);
// this.loggingService.sendInfoLevelMessage(request);
// const startTime: number = Date.now();
// let status: string;
//
// return next.handle(request).pipe(tap(event => {
// status = '';
// if (event instanceof HttpResponse) {
// status = 'succeeded';
// }
// }, error => status = 'failed'),
// finalize(() => {
// const elapsedTime: number = Date.now() - startTime;
// const message: string = `${request.method} request for ${request.urlWithParams} ${status} in ${elapsedTime} ms`;
// this.loggingService.sendInfoLevelMessage(message);
// }));
}
}