mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Reapply "migrate from joi to zod CLSI-CACHE service" GitOrigin-RevId: 638b9e21b8cf18c1733f8a01375dab4099fe5d73
18 lines
427 B
JavaScript
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 }
|