diff --git a/packages/server/src/helper.ts b/packages/server/src/helper.ts index d69d498dcc..2e8abd6f59 100644 --- a/packages/server/src/helper.ts +++ b/packages/server/src/helper.ts @@ -5,12 +5,11 @@ import { Command } from 'commander'; import i18next from 'i18next'; import { DefaultContext, DefaultState } from 'koa'; import bodyParser from 'koa-bodyparser'; +import { BaseError } from 'sequelize'; import Application, { ApplicationOptions } from './application'; import { dataWrapping } from './middlewares/data-wrapping'; import { table2resource } from './middlewares/table2resource'; -import ValidationError from 'sequelize'; - export function createDatabase(options: ApplicationOptions) { if (options.database instanceof Database) { return options.database; @@ -97,12 +96,11 @@ export function createCli(app: Application, options: ApplicationOptions): Comman function registerErrorHandler(app: Application) { app.errorHandler.register( - (err) => err.name == 'SequelizeValidationError', + (err) => err?.errors?.length && err instanceof BaseError, (err, ctx) => { ctx.body = { errors: err.errors.map((err) => ({ message: err.message })), }; - ctx.status = 400; }, );