From 383ee9533f48d5ad9b97fbcb1424b6e1a318a85b Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Fri, 2 Oct 2020 08:50:37 +0200 Subject: [PATCH] :zap: Error if Slack-Requests fail --- packages/nodes-base/nodes/Slack/GenericFunctions.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/nodes-base/nodes/Slack/GenericFunctions.ts b/packages/nodes-base/nodes/Slack/GenericFunctions.ts index 5686d9c0e9..be43f8b185 100644 --- a/packages/nodes-base/nodes/Slack/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Slack/GenericFunctions.ts @@ -35,6 +35,9 @@ export async function slackApiRequest(this: IExecuteFunctions | IExecuteSingleFu delete options.qs; } try { + + let response: any; // tslint:disable-line:no-any + if (authenticationMethod === 'accessToken') { const credentials = this.getCredentials('slackApi'); if (credentials === undefined) { @@ -42,7 +45,7 @@ export async function slackApiRequest(this: IExecuteFunctions | IExecuteSingleFu } options.headers!.Authorization = `Bearer ${credentials.accessToken}`; //@ts-ignore - return await this.helpers.request(options); + response = await this.helpers.request(options); } else { const oAuth2Options: IOAuth2Options = { @@ -50,8 +53,14 @@ export async function slackApiRequest(this: IExecuteFunctions | IExecuteSingleFu property: 'authed_user.access_token', }; //@ts-ignore - return await this.helpers.requestOAuth2.call(this, 'slackOAuth2Api', options, oAuth2Options); + response = await this.helpers.requestOAuth2.call(this, 'slackOAuth2Api', options, oAuth2Options); } + + if (response.ok === false) { + throw new Error('Slack error response: ' + JSON.stringify(response)); + } + + return response; } catch (error) { if (error.statusCode === 401) { // Return a clear error