Files
overleaf-cep/libraries/validation-tools/handleValidationError.js
Eric Mc Sween 3da2d53acb Merge pull request #33413 from overleaf/revert-33040-em-parse-req-errors
Revert "Replace isZodErrorLike with custom error types in request validation"

GitOrigin-RevId: 1f51fe9e14ffabf283f1229552d3887136420f8f
2026-05-06 08:06:41 +00:00

18 lines
457 B
JavaScript

const { isZodErrorLike, fromError } = require('zod-validation-error')
function createHandleValidationError(statusCode = 400) {
return [
(err, req, res, next) => {
if (!isZodErrorLike(err)) {
return next(err)
}
res.status(statusCode).json({ ...fromError(err), statusCode })
},
]
}
const handleValidationError = createHandleValidationError(400)
module.exports = { handleValidationError, createHandleValidationError }