Merge pull request #33490 from overleaf/em-parse-req-errors-2

Reintroduce custom error types in request validation

GitOrigin-RevId: 1985ca04c8fe693fb836b042517d94700343bc46
This commit is contained in:
Eric Mc Sween
2026-05-07 13:32:29 -04:00
committed by Copybot
parent 8c0589df7f
commit 2bb35fafb8
17 changed files with 105 additions and 85 deletions

View File

@@ -5,8 +5,12 @@ import { execFile as execFileCb } from 'node:child_process'
import bodyParser from 'body-parser'
import express from 'express'
import YAML from 'js-yaml'
import { isZodErrorLike } from 'zod-validation-error'
import { ParamsError, parseReq, z } from '@overleaf/validation-tools'
import {
InvalidParamsError,
InvalidRequestError,
parseReq,
z,
} from '@overleaf/validation-tools'
import { expressify } from '@overleaf/promise-utils'
const execFile = promisify(execFileCb)
@@ -474,12 +478,13 @@ app.delete(
)
app.use((error, req, res, next) => {
if (error instanceof ParamsError) {
if (error instanceof InvalidParamsError) {
res.status(404).json({ error })
} else if (isZodErrorLike(error)) {
res.status(400).json({ error })
} else if (error instanceof InvalidRequestError) {
res.status(400).json({ error: error.zodError })
} else {
next(error)
}
next(error)
})
purgeDataDir()