feat: Implement exposing errors from actions within processor
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import SlackClient from '../index';
|
import SlackClient from '../index';
|
||||||
|
import { IJSONObject } from '@automatisch/types';
|
||||||
|
|
||||||
export default class PostMessageToChannel {
|
export default class PostMessageToChannel {
|
||||||
client: SlackClient;
|
client: SlackClient;
|
||||||
@@ -8,6 +9,14 @@ export default class PostMessageToChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async run(channelId: string, text: string) {
|
async run(channelId: string, text: string) {
|
||||||
|
const message: {
|
||||||
|
data: IJSONObject | null;
|
||||||
|
error: IJSONObject | null;
|
||||||
|
} = {
|
||||||
|
data: null,
|
||||||
|
error: null,
|
||||||
|
};
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
Authorization: `Bearer ${this.client.connection.formattedData.accessToken}`,
|
Authorization: `Bearer ${this.client.connection.formattedData.accessToken}`,
|
||||||
};
|
};
|
||||||
@@ -23,12 +32,13 @@ export default class PostMessageToChannel {
|
|||||||
{ headers }
|
{ headers }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.data.ok === 'false') {
|
message.error = response?.integrationError;
|
||||||
throw new Error(
|
message.data = response?.data?.message;
|
||||||
`Error occured while posting a message to channel: ${response.data.error}`
|
|
||||||
);
|
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' },
|
executionId: { type: 'string', format: 'uuid' },
|
||||||
stepId: { type: 'string' },
|
stepId: { type: 'string' },
|
||||||
dataIn: { type: 'object' },
|
dataIn: { type: 'object' },
|
||||||
dataOut: { type: 'object' },
|
dataOut: { type: ['object', 'null'] },
|
||||||
status: { type: 'string', enum: ['success', 'failure'] },
|
status: { type: 'string', enum: ['success', 'failure'] },
|
||||||
errorDetails: { type: ['object', 'null'] },
|
errorDetails: { type: ['object', 'null'] },
|
||||||
},
|
},
|
||||||
|
@@ -77,7 +77,14 @@ class Processor {
|
|||||||
|
|
||||||
let previousExecutionStep: ExecutionStep;
|
let previousExecutionStep: ExecutionStep;
|
||||||
const priorExecutionSteps: ExecutionSteps = {};
|
const priorExecutionSteps: ExecutionSteps = {};
|
||||||
let fetchedActionData = {};
|
|
||||||
|
let fetchedActionData: {
|
||||||
|
data: IJSONObject | null;
|
||||||
|
error: IJSONObject | null;
|
||||||
|
} = {
|
||||||
|
data: null,
|
||||||
|
error: null,
|
||||||
|
};
|
||||||
|
|
||||||
for await (const step of steps) {
|
for await (const step of steps) {
|
||||||
if (!step.appKey) continue;
|
if (!step.appKey) continue;
|
||||||
@@ -101,13 +108,25 @@ class Processor {
|
|||||||
fetchedActionData = await command.run();
|
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
|
previousExecutionStep = await execution
|
||||||
.$relatedQuery('executionSteps')
|
.$relatedQuery('executionSteps')
|
||||||
.insertAndFetch({
|
.insertAndFetch({
|
||||||
stepId: id,
|
stepId: id,
|
||||||
status: 'success',
|
status: 'success',
|
||||||
dataIn: isTrigger ? rawParameters : computedParameters,
|
dataIn: isTrigger ? rawParameters : computedParameters,
|
||||||
dataOut: isTrigger ? data : fetchedActionData,
|
dataOut: isTrigger ? data : fetchedActionData.data,
|
||||||
});
|
});
|
||||||
|
|
||||||
priorExecutionSteps[id] = previousExecutionStep;
|
priorExecutionSteps[id] = previousExecutionStep;
|
||||||
|
Reference in New Issue
Block a user