mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Merge pull request #30053 from overleaf/acf-migration4-controllers-and-params
(4) Update controllers and tests for Zod migration GitOrigin-RevId: 876fd64f96e1f5d7244ac1d45053c7db9857d46b
This commit is contained in:
committed by
Copybot
parent
0efb28baa7
commit
65c164c73d
@@ -1,17 +1,17 @@
|
||||
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)
|
||||
}
|
||||
function createHandleValidationError(statusCode = 400) {
|
||||
return [
|
||||
(err, req, res, next) => {
|
||||
if (!isZodErrorLike(err)) {
|
||||
return next(err)
|
||||
}
|
||||
|
||||
res.status(400).json({ ...fromError(err), statusCode: 400 })
|
||||
},
|
||||
]
|
||||
res.status(statusCode).json({ ...fromError(err), statusCode })
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
module.exports = { handleValidationError }
|
||||
const handleValidationError = createHandleValidationError(400)
|
||||
|
||||
module.exports = { handleValidationError, createHandleValidationError }
|
||||
|
||||
Reference in New Issue
Block a user