I have an AWS step-function/state-machine of Lambda functions written primarily in Javascript (although one is in Java) and I'd like to manage the error processing better.
I have no problem with having an error condition being caught and then forwarded to another state in the flow. So for instance, the following state definition in my state machine passes execution to the NotifyOfError state where I am able to email and sms appropriately about the error state.
Closure:
Type: Task
Resource: >-
arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:xxx-services-${opt:stage}-transportClosure
Next: WaitForCloudWatch
Catch:
- ErrorEquals:
- "States.ALL"
ResultPath: "$.error-info"
Next: NotifyOfError
However, rather than hand ALL errors to this one state there are a few errors I'd like handle differently. So at first I thought that if I threw a Javascript/Node error with a given "name" then that name would be something I could branch off of in the ErrorEquals configuration. Example:
catch(e) {
if (e.message.indexOf('something') !== -1) {
e.name = "SomethingError";
throw e;
}
but soon realized that name was only being prepended to the Cause portion of the step-function and not something that would branch. I then tried extending the base Error class like so:
export default class UndefinedAssignment extends Error {
constructor(e: Error) {
super(e.message);
this.stack = e.stack;
}
}
but throwing this error actually did nothing, meaning that by the time it showed up in the Step Function the Error's type was still just "Error":
"error-info": {
"Error": "Error",
"Cause": "{\"errorMessage\":\"Error: the message",\"errorType\":\"Error\",\"stackTrace\":[\"db.set.catch.e (/var/task/lib/prepWorker/Handler.js:247:23)\",\"process._tickDomainCallback (internal/process/next_tick.js:135:7)\"]}"
}
So I'm still unclear how I can distinguish errors sourced in Node that are branchable within the step function.
Note: with Java, it appears it does pickup the error class correctly (although I've done far less testing on the Java side)