Skip to content

Commit

Permalink
delete some duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed May 2, 2023
1 parent 8c28767 commit ef0e200
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions packages/core/src/NodeExecuteFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1207,28 +1207,26 @@ export async function requestOAuth2(
throw error;
});
}
const tokenExpiredStatusCode =
oAuth2Options?.tokenExpiredStatusCode === undefined
? 401
: oAuth2Options?.tokenExpiredStatusCode;

return this.helpers
.request(newRequestOptions)
.then((response) => {
const requestOptions = newRequestOptions as any;
if (
requestOptions.resolveWithFullResponse === true &&
requestOptions.simple === false &&
response.statusCode ===
(oAuth2Options?.tokenExpiredStatusCode === undefined
? 401
: oAuth2Options?.tokenExpiredStatusCode)
response.statusCode === tokenExpiredStatusCode
) {
throw response;
}
return response;
})
.catch(async (error: IResponseError) => {
const statusCodeReturned =
oAuth2Options?.tokenExpiredStatusCode === undefined
? 401
: oAuth2Options?.tokenExpiredStatusCode;
if (error.statusCode === statusCodeReturned) {
if (error.statusCode === tokenExpiredStatusCode) {
// Token is probably not valid anymore. So try refresh it.
const tokenRefreshOptions: IDataObject = {};
if (oAuth2Options?.includeCredentialsOnRefreshOnBody) {
Expand Down

0 comments on commit ef0e200

Please sign in to comment.