aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--backend/src/api/routes/index.ts24
1 files changed, 16 insertions, 8 deletions
diff --git a/backend/src/api/routes/index.ts b/backend/src/api/routes/index.ts
index 86eec0bc5..287b53f61 100644
--- a/backend/src/api/routes/index.ts
+++ b/backend/src/api/routes/index.ts
@@ -77,7 +77,7 @@ export function addApiRoutes(app: Application): void {
function applyTsRestApiRoutes(app: IRouter): void {
createExpressEndpoints(contract, router, app, {
jsonQuery: true,
- requestValidationErrorHandler(err, _req, res, next) {
+ requestValidationErrorHandler(err, req, res, _next) {
let message: string | undefined = undefined;
let validationErrors: string[] | undefined = undefined;
@@ -90,16 +90,24 @@ function applyTsRestApiRoutes(app: IRouter): void {
} else if (err.body?.issues !== undefined) {
message = "Invalid request data schema";
validationErrors = err.body.issues.map(prettyErrorMessage);
- }
-
- if (message !== undefined) {
- res
- .status(422)
- .json({ message, validationErrors } as MonkeyValidationError);
+ } else if (err.headers?.issues !== undefined) {
+ message = "Invalid header schema";
+ validationErrors = err.headers.issues.map(prettyErrorMessage);
} else {
- next();
+ Logger.error(
+ `Unknown validation error for ${req.method} ${
+ req.path
+ }: ${JSON.stringify(err)}`
+ );
+ res
+ .status(500)
+ .json({ message: "Unknown validation error. Contact support." });
return;
}
+
+ res
+ .status(422)
+ .json({ message, validationErrors } as MonkeyValidationError);
},
globalMiddleware: [authenticateTsRestRequest()],
});