From b873eec2ad46a51bfb4508d9366a9b337cf60292 Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Tue, 28 Sep 2021 14:41:12 +0200 Subject: [PATCH 1/2] Fixed refresh token to work correctly with Axios --- packages/core/src/Interfaces.ts | 6 +++++- packages/core/src/NodeExecuteFunctions.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/core/src/Interfaces.ts b/packages/core/src/Interfaces.ts index 94f940ed0a..7548b4c944 100644 --- a/packages/core/src/Interfaces.ts +++ b/packages/core/src/Interfaces.ts @@ -106,7 +106,11 @@ export interface IPollFunctions extends IPollFunctionsBase { } export interface IResponseError extends Error { - statusCode?: number; + status?: number; // this is how the request library returns + response?: { + // this is how Axios returns + status: number; + }; } export interface ITriggerFunctions extends ITriggerFunctionsBase { diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/NodeExecuteFunctions.ts index af9dd3ed56..48c7cb1c76 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/NodeExecuteFunctions.ts @@ -673,7 +673,7 @@ export async function requestOAuth2( ? 401 : oAuth2Options?.tokenExpiredStatusCode; - if (error.statusCode === statusCodeReturned) { + if (error.response?.status === statusCodeReturned || error.status === statusCodeReturned) { // Token is probably not valid anymore. So try refresh it. const tokenRefreshOptions: IDataObject = {}; From 694ec64330970bb995cefcad6cf973659cdb2932 Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Tue, 28 Sep 2021 15:20:01 +0200 Subject: [PATCH 2/2] Changed the error handling location --- packages/core/src/Interfaces.ts | 6 +----- packages/core/src/NodeExecuteFunctions.ts | 3 ++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/core/src/Interfaces.ts b/packages/core/src/Interfaces.ts index 7548b4c944..94f940ed0a 100644 --- a/packages/core/src/Interfaces.ts +++ b/packages/core/src/Interfaces.ts @@ -106,11 +106,7 @@ export interface IPollFunctions extends IPollFunctionsBase { } export interface IResponseError extends Error { - status?: number; // this is how the request library returns - response?: { - // this is how Axios returns - status: number; - }; + statusCode?: number; } export interface ITriggerFunctions extends ITriggerFunctionsBase { diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/NodeExecuteFunctions.ts index 48c7cb1c76..09d29f76c4 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/NodeExecuteFunctions.ts @@ -415,6 +415,7 @@ async function proxyRequestToAxios( } }) .catch((error) => { + error.statusCode = error.response.status; reject(error); }); }); @@ -673,7 +674,7 @@ export async function requestOAuth2( ? 401 : oAuth2Options?.tokenExpiredStatusCode; - if (error.response?.status === statusCodeReturned || error.status === statusCodeReturned) { + if (error.statusCode === statusCodeReturned) { // Token is probably not valid anymore. So try refresh it. const tokenRefreshOptions: IDataObject = {};