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 - 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 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", "name": "error-chain",
"version": "0.1.2", "version": "0.1.3",
"main": "index.js", "main": "index.js",
"repository": "git@git.cryto.net:joepie91/node-error-chain.git", "repository": "git@git.cryto.net:joepie91/node-error-chain.git",
"author": "Sven Slootweg <admin@cryto.net>", "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 isErrorConstructor = require("./validators/is-error-constructor");
const isContextSchema = require("./validators/is-context-schema"); 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) { module.exports = function createCustomErrorType(_name, _options) {
let [ name, options ] = validateArguments(arguments, { let [ name, options ] = validateArguments(arguments, {
name: [ required, isString ], name: [ required, isString ],
@ -48,7 +55,7 @@ module.exports = function createCustomErrorType(_name, _options) {
} }
ErrorConstructor._assignDefaultProperties(this); ErrorConstructor._assignDefaultProperties(this);
Object.assign(this, context); safeAssign(this, context);
}; };
ErrorConstructor._assignDefaultProperties = function (errorObject) { ErrorConstructor._assignDefaultProperties = function (errorObject) {
@ -58,7 +65,7 @@ module.exports = function createCustomErrorType(_name, _options) {
options.inheritsFrom._assignDefaultProperties(errorObject); options.inheritsFrom._assignDefaultProperties(errorObject);
} }
Object.assign(errorObject, options.context); safeAssign(errorObject, options.context);
}; };
ErrorConstructor.prototype = Object.create(options.inheritsFrom.prototype); ErrorConstructor.prototype = Object.create(options.inheritsFrom.prototype);

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

Loading…
Cancel
Save