@@ -19,10 +19,7 @@ export class ProblemDetailError extends Error {
19
19
public readonly problem : Static < typeof ProblemDetail >
20
20
constructor ( problem : Omit < Static < typeof ProblemDetail > , '@context' > ) {
21
21
super ( problem . title )
22
- this . problem = {
23
- '@context' : Context . problemDetail . toString ( ) ,
24
- ...problem ,
25
- }
22
+ this . problem = { '@context' : Context . problemDetail . toString ( ) , ...problem }
26
23
this . name = 'ProblemDetailError'
27
24
}
28
25
}
@@ -35,16 +32,16 @@ export const problemResponse = (): MiddlewareObj<
35
32
> => ( {
36
33
onError : async ( req ) => {
37
34
if ( req . response !== undefined ) return
38
- if ( req . error instanceof ValidationFailedError ) {
35
+ if ( req . error instanceof ResponseValidationFailedError ) {
39
36
req . response = aProblem ( {
40
- title : 'Validation failed' ,
41
- status : HttpStatusCode . BAD_REQUEST ,
37
+ title : 'Response validation failed' ,
38
+ status : HttpStatusCode . INTERNAL_SERVER_ERROR ,
42
39
detail : formatTypeBoxErrors ( req . error . errors ) ,
43
40
} )
44
- } else if ( req . error instanceof ResponseValidationFailedError ) {
41
+ } else if ( req . error instanceof ValidationFailedError ) {
45
42
req . response = aProblem ( {
46
- title : 'Response validation failed' ,
47
- status : HttpStatusCode . INTERNAL_SERVER_ERROR ,
43
+ title : 'Validation failed' ,
44
+ status : HttpStatusCode . BAD_REQUEST ,
48
45
detail : formatTypeBoxErrors ( req . error . errors ) ,
49
46
} )
50
47
} else if ( req . error instanceof ProblemDetailError ) {
0 commit comments