Error if Slack-Requests fail

This commit is contained in:
Jan Oberhauser 2020-10-02 08:50:37 +02:00
parent 39c173a272
commit 383ee9533f

View file

@ -35,6 +35,9 @@ export async function slackApiRequest(this: IExecuteFunctions | IExecuteSingleFu
delete options.qs; delete options.qs;
} }
try { try {
let response: any; // tslint:disable-line:no-any
if (authenticationMethod === 'accessToken') { if (authenticationMethod === 'accessToken') {
const credentials = this.getCredentials('slackApi'); const credentials = this.getCredentials('slackApi');
if (credentials === undefined) { if (credentials === undefined) {
@ -42,7 +45,7 @@ export async function slackApiRequest(this: IExecuteFunctions | IExecuteSingleFu
} }
options.headers!.Authorization = `Bearer ${credentials.accessToken}`; options.headers!.Authorization = `Bearer ${credentials.accessToken}`;
//@ts-ignore //@ts-ignore
return await this.helpers.request(options); response = await this.helpers.request(options);
} else { } else {
const oAuth2Options: IOAuth2Options = { const oAuth2Options: IOAuth2Options = {
@ -50,8 +53,14 @@ export async function slackApiRequest(this: IExecuteFunctions | IExecuteSingleFu
property: 'authed_user.access_token', property: 'authed_user.access_token',
}; };
//@ts-ignore //@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) { } catch (error) {
if (error.statusCode === 401) { if (error.statusCode === 401) {
// Return a clear error // Return a clear error