Skip to content

Commit

Permalink
use extendable-error package
Browse files Browse the repository at this point in the history
  • Loading branch information
vilicvane committed Dec 30, 2015
1 parent 0eb787c commit 20f1104
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"dependencies": {
"chalk": "^1.1.1",
"express": "^4.13.3",
"extendable-error": "^0.1.1",
"glob": "^6.0.1",
"hyphenate": "^0.2.1",
"thenfail": "^0.3.17"
Expand Down
10 changes: 4 additions & 6 deletions src/api-error.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import ExtendableError from 'extendable-error';

/**
* APIError class.
*/
export class APIError extends Error {
name = (this.constructor as any).name;
stack: string;

export class APIError extends ExtendableError {
constructor(
public code: number,
public message = APIErrorMessages[code] || APIErrorMessages[APIErrorCode.unknown],
message = APIErrorMessages[code] || APIErrorMessages[APIErrorCode.unknown],
public status = APIError.defaultStatus
) {
super(message);
this.stack = (new Error() as any).stack.replace(/\s+at new APIError .+/, '');
}

static defaultStatus = 500;
Expand Down

0 comments on commit 20f1104

Please sign in to comment.