From d79646f70e9e7f72a49eff7e4cacdf73fb07e7a3 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Thu, 13 Jun 2024 16:07:38 +0300 Subject: [PATCH] fix: Fix potential exception when there is no response Not sure it can happen in real life, but be on the safe side. --- src/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index cba1f3b..003dcfe 100644 --- a/src/index.ts +++ b/src/index.ts @@ -230,7 +230,10 @@ async function onError(instance: AxiosInstance, error: AxiosError) { const onBackoffPromise = new Promise((resolve, reject) => { let delay = 0; // If enabled, check for 'Retry-After' header in response to use as delay - if (config.checkRetryAfter && axiosError.response?.headers['retry-after']) { + if ( + config.checkRetryAfter && + axiosError.response?.headers?.['retry-after'] + ) { const retryAfter = parseRetryAfter( axiosError.response.headers['retry-after'] as string, );