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