I am creating a state machine in AWS. In first state (Lambda) if an Exception is thrown, it is caught and passed on to another lambda for processing. When throwing the exception I have created a custom class inhering from class Exception and having a bool property. The property is set but when the output is received it does not have the property.
public class CustomException : Exception
{
private bool isReprocessed;
public CustomException(String message) : base(message)
{ isReprocessed = true; }
}
Output of Lambda -
{
"errorType" : "CustomException",
"errorMessage": "Custom Exception thrown.",
"stackTrace": [
"at lambdaProcessingFromStepFunction.Function.FunctionHandler(Object input, ILambdaContext context)",
"at lambda_method(Closure , Stream , Stream , ContextInfo )"
],
"cause": {
"errorType" : "CustomException",
"errorMessage" : "Custom Exception thrown.",
"stackTrace" : [
"at lambdaProcessingFromStepFunction.Function.FunctionHandler(Object input, ILambdaContext context)"
]
}
}
There is a layer in AWS which formats all the exceptions in transit between different lambdas or when going to cloudWatch. Just like in majority of frameworks, when you throw an error it's parsed into generic format if you leave the environment it was created in. There are few options, you can catch all exceptions in your lambda itself, and then serialize them to whatever object you want. Or you can put the extra information into the message, and then on another end you parse the message(imagine error codes).
https://docs.aws.amazon.com/lambda/latest/dg/dotnet-exceptions.html
Another option is if there aren't many different cases you can just have differently named exceptions. So, have one exception CustomException, and another one CustomExceptionReprocessed, and then in the state machine, you can bind handlers to specific exception names.