feat: Implement exposing errors from actions within processor
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user