Skip to content

Commit

Permalink
feat: errors module
Browse files Browse the repository at this point in the history
  • Loading branch information
trs committed Nov 22, 2017
1 parent e201e26 commit 9d7c45f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function handle(err) {
const message = err.message || 'Unknown error';
const code = err.code || 1;
console.log(message);

process.exitCode = code;
return false;
}

class UserNotFound extends Error {
constructor() {
super('User not found');
this.code = 404;
}
}

class UserAlreadyExists extends Error {
constructor() {
super('User already exists');
this.code = 400;
}
}

class InvalidUserToken extends Error {
constructor() {
super('User has a non-existant or invalid token');
this.code = 500;
}
}

module.exports = {
handle,

UserNotFound,
InvalidUserToken,
UserAlreadyExists
};

0 comments on commit 9d7c45f

Please sign in to comment.