From 00fb5ccf42cb8c21e75222dffe1c366b34aed150 Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Tue, 16 Apr 2024 10:26:44 +0300 Subject: [PATCH] improved timeout handling --- lib/api.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/api.js b/lib/api.js index 61b483e..b80ae8b 100644 --- a/lib/api.js +++ b/lib/api.js @@ -205,19 +205,24 @@ Api.prototype = { // The request was made and the server responded with a status code // that falls out of the range of 2xx .catch(function (error) { - // if (error.code === "ERR_CANCELED" && abortSignal.aborted) { - // self.errorHandler(error.code, "Request timed out"); - // } + if (error.code === "ERR_CANCELED" && abortSignal.aborted) { + var err = { + Message: "Request timed out", + Code: 408 + }; + self.errorHandler(err.Message, err); + reject(err); + } else { + var resolveArgument = (resolveWithFullResponse) ? + _.extend(error.response, {body: error.response.data}) : error.response.data; - var resolveArgument = (resolveWithFullResponse) ? - _.extend(error.response, {body: error.response.data}) : error.response.data; + if (_.isFunction(callback)) { + callback(resolveArgument, error.response); + } - if (_.isFunction(callback)) { - callback(resolveArgument, error.response); + self.errorHandler(error.message, error.response.data); + reject(resolveArgument); } - - self.errorHandler(error.message, error.response.data); - reject(resolveArgument); }); }); },