Skip to content

Commit

Permalink
Add test case and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
graydenshand authored and gshand committed Dec 19, 2023
1 parent 0d0d6a9 commit 87fd91a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/aws-cdk-lib/aws-stepfunctions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,10 @@ const custom = new sfn.CustomState(this, 'my custom task', {
stateJson,
});

// catch errors with addCatch
const errorHandler = new sfn.Pass(this, 'handle failure');
custom.addCatch(errorHandler);

const chain = sfn.Chain.start(custom)
.next(finalStatus);

Expand Down
37 changes: 37 additions & 0 deletions packages/aws-cdk-lib/aws-stepfunctions/test/custom-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,41 @@ describe('Custom State', () => {
},
);
});

test('can add a catch state to thechain'), () => {
// WHEN
const fail = new sfn.Fail(stack, 'MyFail', { error: 'DidNotWork', cause: 'HumanError' })
const definition = new sfn.CustomState(stack, 'Custom', {
stateJson,
}).addCatch(fail);

// THEN
expect(render(stack, definition)).toStrictEqual(
{
StartAt: 'Custom',
States: {
'Custom': {
Type: 'Task',
Resource: 'arn:aws:states:::dynamodb:putItem',
Parameters: {
TableName: 'MyTable',
Item: {
id: {
S: 'MyEntry',
},
},
},
ResultPath: null,
Catch: {

}
},
'my-pass-state': {
Type: 'Pass',
End: true,
},
},
},
);
};
});

0 comments on commit 87fd91a

Please sign in to comment.