I am trying to intercept request in angular to know if API is taking more than 5 seconds in flight. If API takes more than 5 seconds then a message needs to be displayed like 'Request in progress, it will take a short while'
I am able to calculate time took by API after getting response as below:
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const startTimestamp = +new Date().getTime();
return next.handle(req).pipe(
tap(
(evt: HttpEvent<any>) => {
const endTimestamp: number = +new Date().getTime();
// get the difference
const responseTimes = (endTimestamp - startTimestamp) / 1000;
console.log(`Request took ${responseTimes} ms`);
}
)
}
However, i want to know the time while request is in flight. Any leads will be apprecited.