mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-24 01:29:35 +02:00
(4) Update controllers and tests for Zod migration GitOrigin-RevId: 876fd64f96e1f5d7244ac1d45053c7db9857d46b
18 lines
457 B
JavaScript
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 }
|