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'
22import type { Static } from '@sinclair/typebox'
33import { Context , type ProblemDetail } from '@hello.nrfcloud.com/proto/hello'
44
55export const aProblem = (
66 problem : Omit < Static < typeof ProblemDetail > , '@context' > ,
77 cacheForSeconds : number = 60 ,
8- ) : APIGatewayProxyResultV2 => ( {
8+ ) : APIGatewayProxyStructuredResultV2 => ( {
99 statusCode : problem . status ,
1010 headers : {
1111 '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'
52import type { HttpStatusCode } from '@hello.nrfcloud.com/proto/hello'
63
74export const aResponse = (
@@ -11,7 +8,7 @@ export const aResponse = (
118 } & Record < string , unknown > ,
129 cacheForSeconds : number = 60 ,
1310 headers ?: APIGatewayProxyStructuredResultV2 [ 'headers' ] ,
14- ) : APIGatewayProxyResultV2 => {
11+ ) : APIGatewayProxyStructuredResultV2 => {
1512 const body = result !== undefined ? JSON . stringify ( result ) : undefined
1613 return {
1714 statusCode : status ,
Original file line number Diff line number Diff line change 11import type {
22 APIGatewayProxyEventHeaders ,
3- APIGatewayProxyResultV2 ,
3+ APIGatewayProxyStructuredResultV2 ,
44} from 'aws-lambda'
55import { corsHeaders } from './corsHeaders.js'
66
77export const corsResponse = ( event : {
88 headers : APIGatewayProxyEventHeaders
9- } ) : APIGatewayProxyResultV2 => ( {
9+ } ) : APIGatewayProxyStructuredResultV2 => ( {
1010 statusCode : 200 ,
1111 headers : corsHeaders ( event ) ,
1212} )
Original file line number Diff line number Diff line change @@ -33,22 +33,23 @@ export const problemResponse = (): MiddlewareObj<
3333 LambdaContext
3434> => ( {
3535 onError : async ( req ) => {
36+ if ( req . response !== undefined ) return
3637 if ( req . error instanceof ValidationFailedError ) {
37- return aProblem ( {
38+ req . response = aProblem ( {
3839 title : 'Validation failed' ,
3940 status : HttpStatusCode . BAD_REQUEST ,
4041 detail : formatTypeBoxErrors ( req . error . errors ) ,
4142 } )
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+ } )
4253 }
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- } )
5354 } ,
5455} )
You can’t perform that action at this time.
0 commit comments