Skip to content

Commit f011953

Browse files
committed
fix(problem response): omit @context
1 parent ff599e8 commit f011953

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/problemResponse.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { formatTypeBoxErrors } from '@hello.nrfcloud.com/proto'
22
import {
3+
Context,
34
HttpStatusCode,
45
type ProblemDetail,
56
} from '@hello.nrfcloud.com/proto/hello'
@@ -8,16 +9,19 @@ import type { Static } from '@sinclair/typebox'
89
import type {
910
APIGatewayProxyEventV2,
1011
APIGatewayProxyStructuredResultV2,
11-
Context,
12+
Context as LambdaContext,
1213
} from 'aws-lambda'
1314
import { aProblem } from './aProblem.js'
1415
import { ValidationFailedError } from './validateInput.js'
1516

1617
export class ProblemDetailError extends Error {
1718
public readonly problem: Static<typeof ProblemDetail>
18-
constructor(problem: Static<typeof ProblemDetail>) {
19+
constructor(problem: Omit<Static<typeof ProblemDetail>, '@context'>) {
1920
super(problem.title)
20-
this.problem = problem
21+
this.problem = {
22+
'@context': Context.problemDetail.toString(),
23+
...problem,
24+
}
2125
this.name = 'ProblemDetailError'
2226
}
2327
}
@@ -26,7 +30,7 @@ export const problemResponse = (): MiddlewareObj<
2630
APIGatewayProxyEventV2,
2731
APIGatewayProxyStructuredResultV2,
2832
Error,
29-
Context
33+
LambdaContext
3034
> => ({
3135
onError: async (req) => {
3236
if (req.error instanceof ValidationFailedError) {

0 commit comments

Comments
 (0)