feat: Implement exposing errors from actions within processor

This commit is contained in:
Faruk AYDIN
2022-09-27 12:20:16 +03:00
parent 45cce9956b
commit e149d47135
3 changed files with 37 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
import SlackClient from '../index';
import { IJSONObject } from '@automatisch/types';
export default class PostMessageToChannel {
client: SlackClient;
@@ -8,6 +9,14 @@ export default class PostMessageToChannel {
}
async run(channelId: string, text: string) {
const message: {
data: IJSONObject | null;
error: IJSONObject | null;
} = {
data: null,
error: null,
};
const headers = {
Authorization: `Bearer ${this.client.connection.formattedData.accessToken}`,
};
@@ -23,12 +32,13 @@ export default class PostMessageToChannel {
{ headers }
);
if (response.data.ok === 'false') {
throw new Error(
`Error occured while posting a message to channel: ${response.data.error}`
);
message.error = response?.integrationError;
message.data = response?.data?.message;
if (response.data.ok === false) {
message.error = response.data;
}
return response.data.message;
return message;
}
}