Merge pull request #552 from automatisch/fix/expose-errors-as-execute-flow

fix: Expose errors within execute flow mutation
This commit is contained in:
Ömer Faruk Aydın
2022-09-28 10:42:41 +03:00
committed by GitHub
4 changed files with 22 additions and 9 deletions

View File

@@ -24,7 +24,7 @@ const executeFlow = async (
const flow = await untilStep.$relatedQuery('flow'); const flow = await untilStep.$relatedQuery('flow');
const data = await new Processor(flow, { const executionStep = await new Processor(flow, {
untilStep, untilStep,
testRun: true, testRun: true,
}).run(); }).run();
@@ -33,7 +33,11 @@ const executeFlow = async (
status: 'completed', status: 'completed',
}); });
return { data, step: untilStep }; if (executionStep.errorDetails) {
throw new Error(JSON.stringify(executionStep.errorDetails));
}
return { data: executionStep.dataOut, step: untilStep };
}; };
export default executeFlow; export default executeFlow;

View File

@@ -160,11 +160,7 @@ class Processor {
.orderBy('created_at', 'desc') .orderBy('created_at', 'desc')
.first(); .first();
if (lastExecutionStepFromFirstExecution.errorDetails) { return lastExecutionStepFromFirstExecution;
return lastExecutionStepFromFirstExecution.errorDetails;
} else {
return lastExecutionStepFromFirstExecution?.dataOut;
}
} }
async getInitialTriggerData(step: Step) { async getInitialTriggerData(step: Step) {

View File

@@ -25,6 +25,19 @@ type TestSubstepProps = {
step: IStep; step: IStep;
}; };
function serializeErrors(graphQLErrors: any) {
return graphQLErrors?.map((error: Record<string, unknown>) => {
try {
return {
...error,
message: (<pre style={{ margin: 0 }}>{JSON.stringify(JSON.parse(error.message as string), null, 2)}</pre>),
}
} catch {
return error;
}
})
}
function TestSubstep(props: TestSubstepProps): React.ReactElement { function TestSubstep(props: TestSubstepProps): React.ReactElement {
const { const {
substep, substep,
@@ -81,7 +94,7 @@ function TestSubstep(props: TestSubstepProps): React.ReactElement {
<Collapse in={expanded} timeout="auto" unmountOnExit> <Collapse in={expanded} timeout="auto" unmountOnExit>
<ListItem sx={{ pt: 2, pb: 3, flexDirection: 'column', alignItems: 'flex-start' }}> <ListItem sx={{ pt: 2, pb: 3, flexDirection: 'column', alignItems: 'flex-start' }}>
{error?.graphQLErrors?.length && <Alert severity="error" sx={{ mb: 1, fontWeight: 500, width: '100%' }}> {error?.graphQLErrors?.length && <Alert severity="error" sx={{ mb: 1, fontWeight: 500, width: '100%' }}>
{error?.graphQLErrors.map((error) => (<>{error.message}<br /></>))} {serializeErrors(error.graphQLErrors).map((error: any) => (<div>{error.message}</div>))}
</Alert>} </Alert>}
{hasNoOutput && ( {hasNoOutput && (

View File

@@ -49,7 +49,7 @@ const createErrorLink = (callback: CreateLinkOptions['onError']): ApolloLink =>
}); });
// eslint-disable-next-line @typescript-eslint/no-empty-function // eslint-disable-next-line @typescript-eslint/no-empty-function
const noop = () => {}; const noop = () => { };
const createLink = (options: CreateLinkOptions): ApolloLink => { const createLink = (options: CreateLinkOptions): ApolloLink => {
const { const {