mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Merge pull request #29369 from overleaf/mfb-from-joi-to-zod-clsi-cache
migrate from joi to zod CLSI-CACHE service GitOrigin-RevId: b583431a902a1183235cb91a270f4123a5a7e547
This commit is contained in:
committed by
Copybot
parent
5a242cd4ac
commit
1720314726
17
libraries/validation-tools/handleValidationError.js
Normal file
17
libraries/validation-tools/handleValidationError.js
Normal file
@@ -0,0 +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)
|
||||
}
|
||||
|
||||
res.status(400).json({ ...fromError(err), statusCode: 400 })
|
||||
},
|
||||
]
|
||||
|
||||
module.exports = { handleValidationError }
|
||||
@@ -2,10 +2,12 @@ const { ParamsError } = require('./Errors')
|
||||
const { z } = require('zod')
|
||||
const { zz } = require('./zodHelpers')
|
||||
const { validateReq } = require('./validateReq')
|
||||
const { handleValidationError } = require('./handleValidationError')
|
||||
|
||||
module.exports = {
|
||||
z,
|
||||
zz,
|
||||
validateReq,
|
||||
handleValidationError,
|
||||
ParamsError,
|
||||
}
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
"dependencies": {
|
||||
"@overleaf/o-error": "*",
|
||||
"mongodb": "^6.12.0",
|
||||
"zod": "^4.1.8"
|
||||
"zod": "^4.1.8",
|
||||
"zod-validation-error": "^4.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.0.4",
|
||||
|
||||
Reference in New Issue
Block a user