@@ -38,32 +38,48 @@ public static APIGatewayProxyResponse ToApiGatewayProxyResponse(this InvokeRespo
38
38
}
39
39
catch
40
40
{
41
- if ( emulatorMode == ApiGatewayEmulatorMode . Rest )
41
+ return ToApiGatewayErrorResponse ( emulatorMode ) ;
42
+ }
43
+ }
44
+
45
+ /// <summary>
46
+ /// Creates an API Gateway error response based on the emulator mode.
47
+ /// </summary>
48
+ /// <param name="emulatorMode">The API Gateway emulator mode (Rest or Http).</param>
49
+ /// <returns>An APIGatewayProxyResponse object representing the error response.</returns>
50
+ /// <remarks>
51
+ /// This method generates different error responses based on the API Gateway emulator mode:
52
+ /// - For Rest mode: Returns a response with StatusCode 502 and a generic error message.
53
+ /// - For Http mode: Returns a response with StatusCode 500 and a generic error message.
54
+ /// Both responses include a Content-Type header set to application/json.
55
+ /// </remarks>
56
+ public static APIGatewayProxyResponse ToApiGatewayErrorResponse ( ApiGatewayEmulatorMode emulatorMode )
57
+ {
58
+ if ( emulatorMode == ApiGatewayEmulatorMode . Rest )
59
+ {
60
+ return new APIGatewayProxyResponse
42
61
{
43
- return new APIGatewayProxyResponse
44
- {
45
- StatusCode = 502 ,
46
- Body = "{\" message\" :\" Internal server error\" }" ,
47
- Headers = new Dictionary < string , string >
62
+ StatusCode = 502 ,
63
+ Body = "{\" message\" :\" Internal server error\" }" ,
64
+ Headers = new Dictionary < string , string >
48
65
{
49
66
{ "Content-Type" , "application/json" }
50
67
} ,
51
- IsBase64Encoded = false
52
- } ;
53
- }
54
- else
68
+ IsBase64Encoded = false
69
+ } ;
70
+ }
71
+ else
72
+ {
73
+ return new APIGatewayProxyResponse
55
74
{
56
- return new APIGatewayProxyResponse
57
- {
58
- StatusCode = 500 ,
59
- Body = "{\" message\" :\" Internal Server Error\" }" ,
60
- Headers = new Dictionary < string , string >
75
+ StatusCode = 500 ,
76
+ Body = "{\" message\" :\" Internal Server Error\" }" ,
77
+ Headers = new Dictionary < string , string >
61
78
{
62
79
{ "Content-Type" , "application/json" }
63
80
} ,
64
- IsBase64Encoded = false
65
- } ;
66
- }
81
+ IsBase64Encoded = false
82
+ } ;
67
83
}
68
84
}
69
85
@@ -137,16 +153,7 @@ private static APIGatewayHttpApiV2ProxyResponse ToHttpApiV2Response(string respo
137
153
catch
138
154
{
139
155
// If deserialization fails, return Internal Server Error
140
- return new APIGatewayHttpApiV2ProxyResponse
141
- {
142
- StatusCode = 500 ,
143
- Body = "{\" message\" :\" Internal Server Error\" }" ,
144
- Headers = new Dictionary < string , string >
145
- {
146
- { "Content-Type" , "application/json" }
147
- } ,
148
- IsBase64Encoded = false
149
- } ;
156
+ return ToHttpApiV2ErrorResponse ( ) ;
150
157
}
151
158
}
152
159
@@ -177,4 +184,29 @@ private static APIGatewayHttpApiV2ProxyResponse ToHttpApiV2Response(string respo
177
184
} ;
178
185
}
179
186
187
+ /// <summary>
188
+ /// Creates a standard HTTP API v2 error response.
189
+ /// </summary>
190
+ /// <returns>An APIGatewayHttpApiV2ProxyResponse object representing the error response.</returns>
191
+ /// <remarks>
192
+ /// This method generates a standard error response for HTTP API v2:
193
+ /// - StatusCode is set to 500 (Internal Server Error).
194
+ /// - Body contains a JSON string with a generic error message.
195
+ /// - Headers include a Content-Type set to application/json.
196
+ /// - IsBase64Encoded is set to false.
197
+ /// </remarks>
198
+ public static APIGatewayHttpApiV2ProxyResponse ToHttpApiV2ErrorResponse ( )
199
+ {
200
+ return new APIGatewayHttpApiV2ProxyResponse
201
+ {
202
+ StatusCode = 500 ,
203
+ Body = "{\" message\" :\" Internal Server Error\" }" ,
204
+ Headers = new Dictionary < string , string >
205
+ {
206
+ { "Content-Type" , "application/json" }
207
+ } ,
208
+ IsBase64Encoded = false
209
+ } ;
210
+ }
211
+
180
212
}
0 commit comments