diff --git a/package.json b/package.json index 5b458c4..c5c4508 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wms-core", - "version": "0.20.5-rc.2", + "version": "0.20.5-rc.3", "description": "Node web application framework and toolbelt.", "repository": "https://gitlab.com/ArisuOngaku/wms-core", "author": "Alice Gaudon ", diff --git a/src/db/Validator.ts b/src/db/Validator.ts index 4888ac9..14fb394 100644 --- a/src/db/Validator.ts +++ b/src/db/Validator.ts @@ -2,6 +2,7 @@ import Model from "./Model"; import ModelQuery, {WhereTest} from "./ModelQuery"; import {Connection} from "mysql"; import {Type} from "../Utils"; +import {ServerError} from "../HttpError"; export default class Validator { private readonly steps: ValidationStep[] = []; @@ -27,8 +28,17 @@ export default class Validator { for (const step of this.steps) { if (onlyFormat && !step.isFormat) continue; - const result = step.verifyStep(value, thingName, connection); - if ((result === false || result instanceof Promise && (await result) === false) && step.throw) { + let result; + try { + result = step.verifyStep(value, thingName, connection); + if (result instanceof Promise) { + result = await result; + } + } catch (e) { + throw new ServerError(`An error occurred while validating ${thingName} with value "${value}".`, e); + } + + if (result === false && step.throw) { const error: ValidationError = step.throw(); error.rawValueToHuman = this.rawValueToHuman; error.thingName = thingName;