In my react redux application, using saga and superagent client to make asynchronous https api calls.
Api stays in pending state for around 4-5 secs and then below is timing analysis i got shows took miliseconds to respond. but on clock it took 5 secs around. why is this lag. this happens even if no other parallel requests are there
and if i hit the same api through postman or curl. respond faster in ms.
Below is the api client code:
constructor() {
methods.forEach(
method =>
(this[method] = (
path: string,
{ params, data, timeout, authToken }: APIRequest = {}
) =>
new Promise((resolve, reject) => {
const request = superagent[method](formatUrl(path));
request.timeout(timeout || 60000);
request.set('Authorization', authToken || this.getToken());
if (params) {
request.query(params);
}
if (data) {
request.send(data);
}
request.then((body: Response) => {
resolve(body.body)
}).catch((err: ResponseError) => {
// HACK to redirect to session expired
if (err.status === 401) {
if (window.location.href.indexOf('/customer/') > -1) {
window.history.pushState('', '', '/customer/session-expired')
} else {
window.history.pushState('', '', '/designer/session-expired')
}
}
reject(err)
});
}))
);
}
Below is the saga code to call api:
const result = yield SpacecraftBackendClient.post(
`/api/v1.0/xyz/${abc}/init3D`,
{
data: {
abc,
sessionId,
xyz: convertConnectionType(controller)
}
},
);
yield takeLatest(cartActionTypes.INIT_3D, init3D);