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;
|
||||
}
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ class ExecutionStep extends Base {
|
||||
executionId: { type: 'string', format: 'uuid' },
|
||||
stepId: { type: 'string' },
|
||||
dataIn: { type: 'object' },
|
||||
dataOut: { type: 'object' },
|
||||
dataOut: { type: ['object', 'null'] },
|
||||
status: { type: 'string', enum: ['success', 'failure'] },
|
||||
errorDetails: { type: ['object', 'null'] },
|
||||
},
|
||||
|
@@ -77,7 +77,14 @@ class Processor {
|
||||
|
||||
let previousExecutionStep: ExecutionStep;
|
||||
const priorExecutionSteps: ExecutionSteps = {};
|
||||
let fetchedActionData = {};
|
||||
|
||||
let fetchedActionData: {
|
||||
data: IJSONObject | null;
|
||||
error: IJSONObject | null;
|
||||
} = {
|
||||
data: null,
|
||||
error: null,
|
||||
};
|
||||
|
||||
for await (const step of steps) {
|
||||
if (!step.appKey) continue;
|
||||
@@ -101,13 +108,25 @@ class Processor {
|
||||
fetchedActionData = await command.run();
|
||||
}
|
||||
|
||||
if (!isTrigger && fetchedActionData.error) {
|
||||
await execution.$relatedQuery('executionSteps').insertAndFetch({
|
||||
stepId: id,
|
||||
status: 'failure',
|
||||
dataIn: computedParameters,
|
||||
dataOut: null,
|
||||
errorDetails: fetchedActionData.error,
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
previousExecutionStep = await execution
|
||||
.$relatedQuery('executionSteps')
|
||||
.insertAndFetch({
|
||||
stepId: id,
|
||||
status: 'success',
|
||||
dataIn: isTrigger ? rawParameters : computedParameters,
|
||||
dataOut: isTrigger ? data : fetchedActionData,
|
||||
dataOut: isTrigger ? data : fetchedActionData.data,
|
||||
});
|
||||
|
||||
priorExecutionSteps[id] = previousExecutionStep;
|
||||
|
Reference in New Issue
Block a user