Arif Khan
Arif Khan

Reputation: 246

Angular Interceptor unable to calculate correct time of API response, when there is multiple request at the same time

Steps to reproduce the issue:

  1. The First API call response is coming in 600ms.
  2. within the first API call response time another 4 API request is going to the interceptor and this process takes another 1 second.

The issue is the interceptor is handling the request as a priority but the First API call response is ready in 600ms but it is returning the response once All the request processes, means around 1.6 seconds which is not the correct calculated time.

The logic to calculate the time of API response.

const startTime = new Date().getTime();

next.handle(req).pipe(
  map((event) => {
     const endTime = new Date().getTime();
     const diff = (endTime - startTime)/1000 + 'Seconds'; 
     return event;
  })
)

Upvotes: 0

Views: 350

Answers (1)

Arif Khan
Arif Khan

Reputation: 246

I got the issue, on continue from one page to another page I have submitted task API. this submit task API has another API call giftcardcompatability, we are calling this API in async/subscribe mode and we are navigating to the next page based on submitTask API call. When the next page start loads that time lot of Splunk call going to the interceptor and all Splunk call in sync/topromise so it is getting registered in the main flow since giftcardcompatability call is async call so that it is getting registered in event loop and event loop executes after the main loop so the response is coming after sync calls.

Upvotes: 1

Related Questions