Files
overleaf-cep/libraries/validation-tools/handleValidationError.js
Maria Florencia Besteiro Gonzalez 8cd2f6ac46 Merge pull request #29485 from overleaf/mfb-from-joi-to-zod-clsi-cache-revert
Reapply "migrate from joi to zod CLSI-CACHE service"

GitOrigin-RevId: 638b9e21b8cf18c1733f8a01375dab4099fe5d73
2025-11-04 09:06:10 +00:00

18 lines
427 B
JavaScript

const { isZodErrorLike, fromError } = require('zod-validation-error')
/**
* @typedef {import('express').ErrorRequestHandler} ErrorRequestHandler
*/
const handleValidationError = [
/** @type {ErrorRequestHandler} */
(err, req, res, next) => {
if (!isZodErrorLike(err)) {
return next(err)
}
res.status(400).json({ ...fromError(err), statusCode: 400 })
},
]
module.exports = { handleValidationError }