File tree Expand file tree Collapse file tree 4 files changed +18
-20
lines changed Expand file tree Collapse file tree 4 files changed +18
-20
lines changed Original file line number Diff line number Diff line change 1
- import type { APIGatewayProxyResultV2 } from 'aws-lambda'
1
+ import type { APIGatewayProxyStructuredResultV2 } from 'aws-lambda'
2
2
import type { Static } from '@sinclair/typebox'
3
3
import { Context , type ProblemDetail } from '@hello.nrfcloud.com/proto/hello'
4
4
5
5
export const aProblem = (
6
6
problem : Omit < Static < typeof ProblemDetail > , '@context' > ,
7
7
cacheForSeconds : number = 60 ,
8
- ) : APIGatewayProxyResultV2 => ( {
8
+ ) : APIGatewayProxyStructuredResultV2 => ( {
9
9
statusCode : problem . status ,
10
10
headers : {
11
11
'content-type' : 'application/problem+json' ,
Original file line number Diff line number Diff line change 1
- import type {
2
- APIGatewayProxyResultV2 ,
3
- APIGatewayProxyStructuredResultV2 ,
4
- } from 'aws-lambda'
1
+ import type { APIGatewayProxyStructuredResultV2 } from 'aws-lambda'
5
2
import type { HttpStatusCode } from '@hello.nrfcloud.com/proto/hello'
6
3
7
4
export const aResponse = (
@@ -11,7 +8,7 @@ export const aResponse = (
11
8
} & Record < string , unknown > ,
12
9
cacheForSeconds : number = 60 ,
13
10
headers ?: APIGatewayProxyStructuredResultV2 [ 'headers' ] ,
14
- ) : APIGatewayProxyResultV2 => {
11
+ ) : APIGatewayProxyStructuredResultV2 => {
15
12
const body = result !== undefined ? JSON . stringify ( result ) : undefined
16
13
return {
17
14
statusCode : status ,
Original file line number Diff line number Diff line change 1
1
import type {
2
2
APIGatewayProxyEventHeaders ,
3
- APIGatewayProxyResultV2 ,
3
+ APIGatewayProxyStructuredResultV2 ,
4
4
} from 'aws-lambda'
5
5
import { corsHeaders } from './corsHeaders.js'
6
6
7
7
export const corsResponse = ( event : {
8
8
headers : APIGatewayProxyEventHeaders
9
- } ) : APIGatewayProxyResultV2 => ( {
9
+ } ) : APIGatewayProxyStructuredResultV2 => ( {
10
10
statusCode : 200 ,
11
11
headers : corsHeaders ( event ) ,
12
12
} )
Original file line number Diff line number Diff line change @@ -33,22 +33,23 @@ export const problemResponse = (): MiddlewareObj<
33
33
LambdaContext
34
34
> => ( {
35
35
onError : async ( req ) => {
36
+ if ( req . response !== undefined ) return
36
37
if ( req . error instanceof ValidationFailedError ) {
37
- return aProblem ( {
38
+ req . response = aProblem ( {
38
39
title : 'Validation failed' ,
39
40
status : HttpStatusCode . BAD_REQUEST ,
40
41
detail : formatTypeBoxErrors ( req . error . errors ) ,
41
42
} )
43
+ } else if ( req . error instanceof ProblemDetailError ) {
44
+ req . response = aProblem ( req . error . problem )
45
+ } else {
46
+ req . response = aProblem ( {
47
+ title :
48
+ req . error instanceof Error
49
+ ? req . error . message
50
+ : 'Internal Server Error' ,
51
+ status : HttpStatusCode . INTERNAL_SERVER_ERROR ,
52
+ } )
42
53
}
43
- if ( req . error instanceof ProblemDetailError ) {
44
- return aProblem ( req . error . problem )
45
- }
46
- return aProblem ( {
47
- title :
48
- req . error instanceof Error
49
- ? req . error . message
50
- : 'Internal Server Error' ,
51
- status : HttpStatusCode . INTERNAL_SERVER_ERROR ,
52
- } )
53
54
} ,
54
55
} )
You can’t perform that action at this time.
0 commit comments