Created
October 12, 2014 09:35
-
-
Save yashprit/8423f773552e7a8a8b8e to your computer and use it in GitHub Desktop.
Error handling in NodeJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//sub object, filename = badrequest.js | |
var Exception = require('./exception') | |
, inherits = require('util').inherits; | |
function BadRequest(message, uiMessage){ | |
var code = 400; | |
Exception.call(this, code, message, uiMessage); | |
} | |
inherits(BadRequest, Exception); | |
BadRequest.prototype.name = "BadRequest"; | |
module.exports = BadRequest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//super object, filename exception.js | |
function HttpError(code, message){ | |
this.message = message; | |
this.stack = new Error().stack; | |
this.uiMessage = uiMessage; | |
this.type = this.name; | |
this.code = code; | |
} | |
HttpError.prototype = Object.create(Error.prototype); | |
HttpError.prototype.printStackTrace = function printStackTrace(){ | |
return this; | |
} | |
module.exports = HttpError; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var BadRequest = require('bad_request.js'); | |
//useage, Application is constant object, contains ui related message | |
Promises.reject(new BadRequest(error.message, Application.ModuleName.usernameNotFound) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment