Created
December 15, 2016 01:42
-
-
Save artlogic/28026869470ac36e2fed4efc55d3e357 to your computer and use it in GitHub Desktop.
Possible testdouble.js regression?
This file contains hidden or 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
'use strict'; | |
// Much of this was inspired by sequelize's error module | |
// https://github.com/sequelize/sequelize/blob/master/lib/errors.js | |
var util = require('util'); | |
var error = {}; | |
// Every built in error inherits from this error | |
error.BaseError = function () { | |
var tmp = Error.apply(this, arguments); | |
tmp.name = this.name = 'BaseError'; | |
this.message = tmp.message; | |
this.status = 500; | |
Error.captureStackTrace(this, this.constructor); | |
}; | |
util.inherits(error.BaseError, Error); | |
error.BaseError.prototype.toJSON = function () { | |
return { | |
type: this.name, | |
message: this.message | |
}; | |
}; | |
// used when the user cannot access something | |
error.AccessDeniedError = function (message) { | |
error.BaseError.call(this, message); | |
this.name = 'AccessDeniedError'; | |
this.status = 403; | |
}; | |
util.inherits(error.AccessDeniedError, error.BaseError); | |
// Used when the user passes in invalid data | |
error.ValidationError = function (message, validations) { | |
error.BaseError.call(this, message); | |
this.name = 'ValidationError'; | |
this.status = 422; | |
if (typeof validations === 'undefined') { | |
validations = null; | |
} | |
this.validations = validations; | |
}; | |
util.inherits(error.ValidationError, error.BaseError); | |
error.ValidationError.prototype.toJSON = function () { | |
var json = error.BaseError.prototype.toJSON.call(this); | |
json.validations = this.validations; | |
return json; | |
}; | |
module.exports = error; |
This file contains hidden or 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
'use strict'; | |
var td = require('testdouble'); | |
var error = td.replace('./error'); | |
var ad = new error.AccessDeniedError('Whoops!'); // works in 1.9.1 and 1.10.0 | |
// for me, in 1.10.0 this returns `error.ValidationError is not a constructor` | |
var vd = new error.ValidationError('Oh no!'); // only works in 1.9.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment