File

src/app/_interceptors/logging.interceptor.ts

Index

Methods

Constructor

constructor(loggingService: LoggingService)
Parameters :
Name Type Optional
loggingService LoggingService No

Methods

intercept
intercept(request: HttpRequest, next: HttpHandler)
Parameters :
Name Type Optional
request HttpRequest<unknown> No
next HttpHandler No
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);
    // }));
  }
}

result-matching ""

    No results matching ""