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:
Anna Claire Fields
2025-12-15 11:05:11 +01:00
committed by Copybot
parent 0efb28baa7
commit 65c164c73d
15 changed files with 687 additions and 198 deletions

View File

@@ -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 }

View File

@@ -3,7 +3,10 @@ const { z } = require('zod')
const { zz } = require('./zodHelpers')
const { validateReq } = require('./validateReq')
const { validateSchema } = require('./validateSchema')
const { handleValidationError } = require('./handleValidationError')
const {
handleValidationError,
createHandleValidationError,
} = require('./handleValidationError')
module.exports = {
z,
@@ -11,5 +14,6 @@ module.exports = {
validateSchema,
validateReq,
handleValidationError,
createHandleValidationError,
ParamsError,
}