Skip to content

Commit

Permalink
Merge pull request #9 from fabrix-app/v1.1
Browse files Browse the repository at this point in the history
[feat] ModelError status codes
  • Loading branch information
scott-wyatt authored Aug 2, 2018
2 parents 0ee8138 + 6a1d83f commit 6371cdd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/errors/ModelError.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export class ModelError extends Error {
public statusCode
public code
public errors

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 6371cdd

Please sign in to comment.