Skip to content

Commit

Permalink
fix(output-validation): 🐛 no output is sent when no validation schema…
Browse files Browse the repository at this point in the history
… is specified
  • Loading branch information
evertdespiegeleer committed Oct 11, 2024
1 parent d5aef7d commit affc9ec
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions packages/core/src/util/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,22 @@ export const endpointToExpressHandler = (endpoint: AnyEndpoint) => {
.getHandler()?.(inputParams, req, res)
.then((responseObj) => {
// Output validation
let postOutputValidationResponseObj: z.output<ReturnType<typeof endpoint.getResponseValidationSchema>> = responseObj
try {
postOutputValidationResponseObj = endpoint.getResponseValidationSchema()?.parse(responseObj)
} catch (error) {
const e = error as z.ZodError
loggerInstance.logger('endpointOutputValidation').error(e)
next(new InternalServerError())
return
let postOutputValidationResponseObj: z.output<
NonNullable<ReturnType<typeof endpoint.getResponseValidationSchema>>
>

const responseValidationSchema = endpoint.getResponseValidationSchema()
if (responseValidationSchema != null) {
try {
postOutputValidationResponseObj = responseValidationSchema.parse(responseObj)
} catch (error) {
const e = error as z.ZodError
loggerInstance.logger('endpointOutputValidation').error(e)
next(new InternalServerError())
return
}
} else {
postOutputValidationResponseObj = responseObj
}

res.header('content-type', endpoint.getResponseContentType())
Expand Down

0 comments on commit affc9ec

Please sign in to comment.