Compare commits

...

4 Commits

@ -3,3 +3,6 @@ benefits of eTry
- you can wrap calls in it, as it's an expression, not a statement like try/catch
note that it does not work with async/await, where you're stuck with the manual approach
TODO:
- Add a (maybe)fromGraphQL utility for converting GraphQL's wrapper errors (with `originalError`) into a standard error chain

@ -1,6 +1,6 @@
{
"name": "error-chain",
"version": "0.1.2",
"version": "0.1.3",
"main": "index.js",
"repository": "git@git.cryto.net:joepie91/node-error-chain.git",
"author": "Sven Slootweg <admin@cryto.net>",

@ -11,6 +11,13 @@ const forbidSpecialProperties = require("./validators/forbid-special-properties"
const isErrorConstructor = require("./validators/is-error-constructor");
const isContextSchema = require("./validators/is-context-schema");
function safeAssign(a, ... rest) {
let previousPrototype = a.__proto__;
Object.assign(a, ... rest);
a.__proto__ = previousPrototype;
return a;
}
module.exports = function createCustomErrorType(_name, _options) {
let [ name, options ] = validateArguments(arguments, {
name: [ required, isString ],
@ -48,7 +55,7 @@ module.exports = function createCustomErrorType(_name, _options) {
}
ErrorConstructor._assignDefaultProperties(this);
Object.assign(this, context);
safeAssign(this, context);
};
ErrorConstructor._assignDefaultProperties = function (errorObject) {
@ -58,7 +65,7 @@ module.exports = function createCustomErrorType(_name, _options) {
options.inheritsFrom._assignDefaultProperties(errorObject);
}
Object.assign(errorObject, options.context);
safeAssign(errorObject, options.context);
};
ErrorConstructor.prototype = Object.create(options.inheritsFrom.prototype);

@ -7,6 +7,5 @@ module.exports = [
"message",
"stack",
"cause",
"__proto__",
"constructor"
];

Loading…
Cancel
Save