|
@@ -1,11 +1,14 @@
|
|
|
-import { isZodErrorLike, fromZodError } from 'zod-validation-error'
|
|
|
|
|
|
|
+import { fromZodError } from 'zod-validation-error'
|
|
|
|
|
+import {
|
|
|
|
|
+ InvalidRequestError,
|
|
|
|
|
+ InvalidParamsError,
|
|
|
|
|
+} from '@overleaf/validation-tools'
|
|
|
import Errors, { NotFoundError } from './Errors.js'
|
|
import Errors, { NotFoundError } from './Errors.js'
|
|
|
import SessionManager from '../Authentication/SessionManager.mjs'
|
|
import SessionManager from '../Authentication/SessionManager.mjs'
|
|
|
import SamlLogHandler from '../SamlLog/SamlLogHandler.mjs'
|
|
import SamlLogHandler from '../SamlLog/SamlLogHandler.mjs'
|
|
|
import HttpErrorHandler from './HttpErrorHandler.mjs'
|
|
import HttpErrorHandler from './HttpErrorHandler.mjs'
|
|
|
import { plainTextResponse } from '../../infrastructure/Response.mjs'
|
|
import { plainTextResponse } from '../../infrastructure/Response.mjs'
|
|
|
import { expressifyErrorHandler } from '@overleaf/promise-utils'
|
|
import { expressifyErrorHandler } from '@overleaf/promise-utils'
|
|
|
-import { ParamsError } from '@overleaf/validation-tools'
|
|
|
|
|
|
|
|
|
|
function notFound(req, res) {
|
|
function notFound(req, res) {
|
|
|
res.status(404)
|
|
res.status(404)
|
|
@@ -42,7 +45,7 @@ async function handleError(error, req, res, next) {
|
|
|
if (shouldSendErrorResponse) {
|
|
if (shouldSendErrorResponse) {
|
|
|
notFound(req, res)
|
|
notFound(req, res)
|
|
|
}
|
|
}
|
|
|
- } else if (error instanceof ParamsError) {
|
|
|
|
|
|
|
+ } else if (error instanceof InvalidParamsError) {
|
|
|
req.logger.setLevel('warn')
|
|
req.logger.setLevel('warn')
|
|
|
if (shouldSendErrorResponse) {
|
|
if (shouldSendErrorResponse) {
|
|
|
notFound(req, res)
|
|
notFound(req, res)
|
|
@@ -104,11 +107,11 @@ async function handleError(error, req, res, next) {
|
|
|
res.status(400)
|
|
res.status(400)
|
|
|
plainTextResponse(res, error.message)
|
|
plainTextResponse(res, error.message)
|
|
|
}
|
|
}
|
|
|
- } else if (isZodErrorLike(error)) {
|
|
|
|
|
|
|
+ } else if (error instanceof InvalidRequestError) {
|
|
|
req.logger.setLevel('warn')
|
|
req.logger.setLevel('warn')
|
|
|
res.status(400)
|
|
res.status(400)
|
|
|
if (shouldSendErrorResponse) {
|
|
if (shouldSendErrorResponse) {
|
|
|
- const validationError = fromZodError(error)
|
|
|
|
|
|
|
+ const validationError = fromZodError(error.zodError)
|
|
|
res.render('general/400', { message: validationError.message })
|
|
res.render('general/400', { message: validationError.message })
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
@@ -126,7 +129,10 @@ async function handleError(error, req, res, next) {
|
|
|
|
|
|
|
|
function handleApiError(err, req, res, next) {
|
|
function handleApiError(err, req, res, next) {
|
|
|
req.logger.addFields({ err })
|
|
req.logger.addFields({ err })
|
|
|
- if (err instanceof Errors.NotFoundError || err instanceof ParamsError) {
|
|
|
|
|
|
|
+ if (
|
|
|
|
|
+ err instanceof Errors.NotFoundError ||
|
|
|
|
|
+ err instanceof InvalidParamsError
|
|
|
|
|
+ ) {
|
|
|
req.logger.setLevel('warn')
|
|
req.logger.setLevel('warn')
|
|
|
res.sendStatus(404)
|
|
res.sendStatus(404)
|
|
|
} else if (
|
|
} else if (
|
|
@@ -141,7 +147,7 @@ function handleApiError(err, req, res, next) {
|
|
|
} else if (err instanceof Errors.ForbiddenError) {
|
|
} else if (err instanceof Errors.ForbiddenError) {
|
|
|
req.logger.setLevel('warn')
|
|
req.logger.setLevel('warn')
|
|
|
res.sendStatus(403)
|
|
res.sendStatus(403)
|
|
|
- } else if (isZodErrorLike(err)) {
|
|
|
|
|
|
|
+ } else if (err instanceof InvalidRequestError) {
|
|
|
req.logger.setLevel('warn')
|
|
req.logger.setLevel('warn')
|
|
|
res.sendStatus(400)
|
|
res.sendStatus(400)
|
|
|
} else {
|
|
} else {
|