Skip to content

Instantly share code, notes, and snippets.

@yeaha
Created July 29, 2013 09:52
Show Gist options
  • Save yeaha/6103298 to your computer and use it in GitHub Desktop.
Save yeaha/6103298 to your computer and use it in GitHub Desktop.
自定义javascript Error类
var http = require('http');
// Http错误
function HttpError(code, msg) {
Error.captureStackTrace(this, arguments.callee);
this.name = arguments.callee.name;
var status = http.STATUS_CODES;
if (!code || !(code in status))
code = 500;
if (!msg)
msg = status[code];
this.message = msg;
this.code = code;
}
HttpError.prototype = Object.create(Error.prototype);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment