AWS Lambda 异常处理未添加自定义属性
AWS Lambda Exception Handling not has custom properties added
我正在 AWS 中创建状态机。在第一个状态 (Lambda) 中,如果抛出异常,它会被捕获并传递给另一个 lambda 进行处理。抛出异常时,我创建了一个自定义 class 继承自 class Exception 并具有 bool 属性。 属性 已设置,但当接收到输出时,它没有 属性。
public class CustomException : Exception
{
private bool isReprocessed;
public CustomException(String message) : base(message)
{ isReprocessed = true; }
}
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)"
]
}
}
AWS 中有一个层,用于格式化在不同 lambda 之间传输或转到 cloudWatch 时的所有异常。就像在大多数框架中一样,当您抛出错误时,如果您离开创建它的环境,它会被解析为通用格式。选项很少,您可以在 lambda 本身中捕获所有异常,然后将它们序列化为您想要的任何对象想。或者您可以将额外的信息放入消息中,然后在另一端解析消息(想象错误代码)。
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.
我正在 AWS 中创建状态机。在第一个状态 (Lambda) 中,如果抛出异常,它会被捕获并传递给另一个 lambda 进行处理。抛出异常时,我创建了一个自定义 class 继承自 class Exception 并具有 bool 属性。 属性 已设置,但当接收到输出时,它没有 属性。
public class CustomException : Exception
{
private bool isReprocessed;
public CustomException(String message) : base(message)
{ isReprocessed = true; }
}
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)"
]
}
}
AWS 中有一个层,用于格式化在不同 lambda 之间传输或转到 cloudWatch 时的所有异常。就像在大多数框架中一样,当您抛出错误时,如果您离开创建它的环境,它会被解析为通用格式。选项很少,您可以在 lambda 本身中捕获所有异常,然后将它们序列化为您想要的任何对象想。或者您可以将额外的信息放入消息中,然后在另一端解析消息(想象错误代码)。
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.