From d92cd69d24406c970de5c58aa265228f1fb8b667 Mon Sep 17 00:00:00 2001 From: MillenniumEarl Date: Tue, 16 Mar 2021 10:20:18 +0100 Subject: [PATCH] Fix errors with 403 head --- src/scripts/network-helper.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/scripts/network-helper.ts b/src/scripts/network-helper.ts index d2d29d3..60194b7 100644 --- a/src/scripts/network-helper.ts +++ b/src/scripts/network-helper.ts @@ -64,7 +64,8 @@ const commonConfig = { jar: shared.session.cookieJar, validateStatus: function (status: number) { return status < 500; // Resolve only if the status code is less than 500 - } + }, + timeout: 5000 }; /** @@ -322,7 +323,8 @@ export async function urlExists(url: string, checkRedirect: boolean = false): Pr * @returns {Promise} Redirect URL or the passed URL */ export async function getUrlRedirect(url: string): Promise { - const response = await axios.head(url); + commonConfig.jar = shared.session.cookieJar; + const response = await axios.head(url, commonConfig); return response.config.url; } @@ -339,9 +341,8 @@ async function axiosUrlExists(url: string): Promise { let valid = false; try { - const response = await axios.head(url, { - timeout: 3000 - }); + commonConfig.jar = shared.session.cookieJar; + const response = await axios.head(url, commonConfig); valid = response && !/4\d\d/.test(response.status.toString()); } catch (error) { // Throw error only if the error is unknown