fix: Sequelize rejectOnEmpty should result in 404 status

This commit is contained in:
Tom Moor
2022-07-26 22:06:47 +01:00
parent b7b1f5e1fd
commit 2794057738
2 changed files with 4 additions and 2 deletions

View File

@@ -14,6 +14,7 @@ if (env.SENTRY_DSN) {
// Validation
"BadRequestError",
"SequelizeValidationError",
"SequelizeEmptyResultError",
"ValidationError",
// Authentication

View File

@@ -1,6 +1,6 @@
import { Context, Next } from "koa";
import { snakeCase } from "lodash";
import { ValidationError } from "sequelize";
import { ValidationError, EmptyResultError } from "sequelize";
export default function errorHandling() {
return async function errorHandlingMiddleware(ctx: Context, next: Next) {
@@ -20,7 +20,8 @@ export default function errorHandling() {
}
}
if (message.match(/Not found/i)) {
if (err instanceof EmptyResultError || message.match(/Not found/i)) {
message = "Resource not found";
ctx.status = 404;
error = "not_found";
}