mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-25 02:00:10 +02:00
Handle Zod errors
GitOrigin-RevId: 0501602e8d9a014987b3cbc89cffd86186995e06
This commit is contained in:
@@ -8,6 +8,8 @@ import methodOverride from 'method-override'
|
||||
import { mongoClient } from './app/js/mongodb.js'
|
||||
import NotificationsController from './app/js/NotificationsController.ts'
|
||||
import HealthCheckController from './app/js/HealthCheckController.js'
|
||||
import { isZodErrorLike } from 'zod-validation-error'
|
||||
import { ParamsError } from '@overleaf/validation-tools'
|
||||
|
||||
const app = express()
|
||||
|
||||
@@ -42,6 +44,22 @@ app.get('/health_check', HealthCheckController.check)
|
||||
|
||||
app.get('*', (req, res) => res.sendStatus(404))
|
||||
|
||||
app.use(handleApiError)
|
||||
|
||||
function handleApiError(err, req, res, next) {
|
||||
req.logger.addFields({ err })
|
||||
if (err instanceof ParamsError) {
|
||||
req.logger.setLevel('warn')
|
||||
res.sendStatus(404)
|
||||
} else if (isZodErrorLike(err)) {
|
||||
req.logger.setLevel('warn')
|
||||
res.sendStatus(400)
|
||||
} else {
|
||||
req.logger.setLevel('error')
|
||||
res.sendStatus(500)
|
||||
}
|
||||
}
|
||||
|
||||
const host = Settings.internal.notifications?.host || '127.0.0.1'
|
||||
const port = Settings.internal.notifications?.port || 3042
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user