File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
Sources/AWSLambdaRuntimeCore Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 1+ //
2+ // LambdaError.swift
3+ //
4+ //
5+ // Created by Ben Rosen on 1/6/24.
6+ //
7+
8+ import Foundation
9+
10+ public struct LambdaError : Error {
11+ let errorType : String
12+ let errorMessage : String
13+
14+ public init ( errorType: String , errorMessage: String ) {
15+ self . errorType = errorType
16+ self . errorMessage = errorMessage
17+ }
18+ }
Original file line number Diff line number Diff line change @@ -69,7 +69,17 @@ internal struct LambdaRuntimeClient {
6969 headers = LambdaRuntimeClient . defaultHeaders
7070 case . failure( let error) :
7171 url += Consts . postErrorURLSuffix
72- let errorResponse = ErrorResponse ( errorType: Consts . functionError, errorMessage: " \( error) " )
72+
73+ /*
74+ If a LambdaError is thrown, we allow a custom errorType to be thrown from the function
75+ */
76+ var errorResponse : ErrorResponse
77+ if let lambdaError = error as? LambdaError {
78+ errorResponse = ErrorResponse ( errorType: lambdaError. errorType, errorMessage: lambdaError. errorMessage)
79+ } else {
80+ errorResponse = ErrorResponse ( errorType: Consts . functionError, errorMessage: " \( error) " )
81+ }
82+
7383 let bytes = errorResponse. toJSONBytes ( )
7484 body = self . allocator. buffer ( capacity: bytes. count)
7585 body!. writeBytes ( bytes)
You can’t perform that action at this time.
0 commit comments