mirror of
https://github.com/swift-server/swift-aws-lambda-runtime.git
synced 2026-05-03 07:22:27 +00:00
9487a09e3a
### Motivation: Fix for Issue [#580](https://github.com/swift-server/swift-aws-lambda-runtime/issues/580), by making it so that the `errorType` in failed requests will be the type of the error entity, rather than a hardcoded string of `FunctionError`. This allows orchestration within step functions that perform retry/catch logic based on different error output types. ### Modifications: At a high level, the issue is that swift-aws-lambda-runtime, when an error is thrown, outputs the errorType as hardcoded to FunctionError. You can see that [here](https://github.com/swift-server/swift-aws-lambda-runtime/blob/main/Sources/AWSLambdaRuntime/LambdaRuntimeClient%2BChannelHandler.swift#L337): ``` let errorResponse = ErrorResponse(errorType: Consts.functionError, errorMessage: "\(error)") ``` This PR changes this for all cases to output the type of the error, rather than the hardcoded string: ``` let errorResponse = ErrorResponse(errorType: "\(type(of: error))", errorMessage: "\(error)") ``` Now, I will show 2 examples with this solution: ``` let runtime = LambdaRuntime { (event: Input, context: LambdaContext) in enum MyTestErrorType: Error { case testError } throw MyTestErrorType.testError } // outputs {"errorType":"MyTestErrorType","errorMessage":"testError"} ``` ``` let dynamoDB: DynamoDB = DynamoDB(client: .init()) let runtime = LambdaRuntime { (event: Input, context: LambdaContext) in let _ = try await dynamoDB.putItem(DynamoDB.PutItemInput(item: [:], tableName: "")) return Output() } // outputs {"errorType":"AWSClientError","errorMessage":"ValidationError: Length of PutItemInput.tableName (0) is less than minimum allowed value 1."} ```