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",
|
||||
|
||||
5
package-lock.json
generated
5
package-lock.json
generated
@@ -541,7 +541,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",
|
||||
@@ -51424,9 +51425,9 @@
|
||||
"@overleaf/promise-utils": "*",
|
||||
"@overleaf/settings": "*",
|
||||
"@overleaf/stream-utils": "*",
|
||||
"@overleaf/validation-tools": "*",
|
||||
"body-parser": "^1.20.3",
|
||||
"bunyan": "^1.8.15",
|
||||
"celebrate": "^15.0.3",
|
||||
"express": "^4.21.2",
|
||||
"p-limit": "^3.1.0"
|
||||
},
|
||||
|
||||
@@ -2,7 +2,6 @@ import express from 'express'
|
||||
import Settings from '@overleaf/settings'
|
||||
import logger from '@overleaf/logger'
|
||||
import metrics from '@overleaf/metrics'
|
||||
import Validation from './Validation.js'
|
||||
import csp, { removeCSPHeaders } from './CSP.mjs'
|
||||
import Router from '../router.mjs'
|
||||
import helmet from 'helmet'
|
||||
@@ -38,6 +37,7 @@ import os from 'node:os'
|
||||
import http from 'node:http'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import serveStaticWrapper from './ServeStaticWrapper.mjs'
|
||||
import { handleValidationError } from '@overleaf/validation-tools'
|
||||
|
||||
const { hasAdminAccess } = AdminAuthorizationHelper
|
||||
const sessionsRedisClient = UserSessionsRedis.client()
|
||||
@@ -356,17 +356,17 @@ const server = http.createServer(app)
|
||||
if (Settings.enabledServices.includes('api')) {
|
||||
logger.debug({}, 'providing api router')
|
||||
app.use(privateApiRouter)
|
||||
app.use(Validation.errorMiddleware)
|
||||
app.use(handleValidationError)
|
||||
app.use(ErrorController.handleApiError)
|
||||
}
|
||||
|
||||
if (Settings.enabledServices.includes('web')) {
|
||||
logger.debug({}, 'providing web router')
|
||||
app.use(publicApiRouter) // public API goes with web router for public access
|
||||
app.use(Validation.errorMiddleware)
|
||||
app.use(handleValidationError)
|
||||
app.use(ErrorController.handleApiError)
|
||||
app.use(webRouter)
|
||||
app.use(Validation.errorMiddleware)
|
||||
app.use(handleValidationError)
|
||||
app.use(ErrorController.handleError)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,22 +7,6 @@ const {
|
||||
zz,
|
||||
ParamsError,
|
||||
} = require('@overleaf/validation-tools')
|
||||
const { isZodErrorLike, fromError } = require('zod-validation-error')
|
||||
|
||||
/**
|
||||
* @typedef {import('express').ErrorRequestHandler} ErrorRequestHandler
|
||||
*/
|
||||
|
||||
const errorMiddleware = [
|
||||
/** @type {ErrorRequestHandler} */
|
||||
(err, req, res, next) => {
|
||||
if (!isZodErrorLike(err)) {
|
||||
return next(err)
|
||||
}
|
||||
|
||||
res.status(400).json({ ...fromError(err), statusCode: 400 })
|
||||
},
|
||||
]
|
||||
|
||||
const validateReqWeb = (req, schema) => {
|
||||
try {
|
||||
@@ -37,7 +21,6 @@ const validateReqWeb = (req, schema) => {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
errorMiddleware,
|
||||
validateReq: validateReqWeb,
|
||||
z,
|
||||
zz,
|
||||
|
||||
Reference in New Issue
Block a user