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