From 6a1d83fb7f3ebbac64bde3e087ba7c55b6345e29 Mon Sep 17 00:00:00 2001 From: scott-wyatt Date: Thu, 2 Aug 2018 18:09:53 -0400 Subject: [PATCH] [feat] ModelError status codes --- lib/errors/ModelError.ts | 15 +++++++++++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/errors/ModelError.ts b/lib/errors/ModelError.ts index 5a3bde1..b2b7056 100755 --- a/lib/errors/ModelError.ts +++ b/lib/errors/ModelError.ts @@ -1,4 +1,5 @@ export class ModelError extends Error { + public statusCode public code public errors @@ -8,6 +9,20 @@ export class ModelError extends Error { this.name = 'Model error' this.errors = errors + switch (this.code) { + case 'E_NOT_FOUND': { + this.statusCode = '404' + break + } + case 'E_BAD_REQUEST': { + this.statusCode = '400' + break + } + default: { + this.statusCode = '500' + } + } + Object.defineProperty(ModelError.prototype, 'message', { configurable: true, enumerable: true diff --git a/package-lock.json b/package-lock.json index 853256d..548ddca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@fabrix/spool-sequelize", - "version": "1.1.5", + "version": "1.1.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 8861467..07a7bac 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fabrix/spool-sequelize", - "version": "1.1.5", + "version": "1.1.6", "description": "Spool - Datastore Spool for Sequelize.js http://sequelizejs.com", "scripts": { "build": "tsc -p ./lib/tsconfig.release.json",