jsonify-error
Advanced tools
Comparing version 1.3.1 to 1.4.0
@@ -9,2 +9,11 @@ # Changelog | ||
## [1.4.0] - 2018-10-27 | ||
### Added | ||
- `jsonifyError.log(error)` function | ||
- `jsonifyError.overrideErrorMethods()` function (enabling powerful `.toJSON()` and `.toString()` methods on errors) | ||
- Dev: added node and browser tests (with Travis CI!) | ||
### Changed | ||
- Improved README | ||
- Dev: separate the library in multiple files | ||
## [1.3.1] - 2018-08-15 | ||
@@ -58,3 +67,4 @@ ### Changed | ||
[Unreleased]: https://github.com/papb/jsonify-error/compare/v1.3.1...HEAD | ||
[Unreleased]: https://github.com/papb/jsonify-error/compare/v1.4.0...HEAD | ||
[1.4.0]: https://github.com/papb/jsonify-error/compare/v1.3.1...v1.4.0 | ||
[1.3.1]: https://github.com/papb/jsonify-error/compare/v1.3.0...v1.3.1 | ||
@@ -61,0 +71,0 @@ [1.3.0]: https://github.com/papb/jsonify-error/compare/v1.2.2...v1.3.0 |
@@ -9,5 +9,27 @@ (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
var jsonifyError = require("./lib/jsonify-error"); | ||
var overrideConsole = require("./lib/override-console"); | ||
var overrideErrorMethods = require("./lib/override-error-methods"); | ||
var log = require("./lib/log"); | ||
function getSuperclasses(obj) { | ||
module.exports = jsonifyError; | ||
module.exports.overrideConsole = overrideConsole; | ||
module.exports.overrideErrorMethods = overrideErrorMethods; | ||
module.exports.log = log; | ||
},{"./lib/jsonify-error":5,"./lib/log":3,"./lib/override-console":6,"./lib/override-error-methods":7}],3:[function(require,module,exports){ | ||
"use strict"; | ||
var toString = require("./../to-string"); | ||
module.exports = function log(error) { | ||
var amountOfSpaces = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; | ||
console.error(toString(error, amountOfSpaces)); | ||
}; | ||
},{"./../to-string":8}],4:[function(require,module,exports){ | ||
"use strict"; | ||
module.exports = function getSuperclasses(obj) { | ||
var superclasses = []; | ||
@@ -21,5 +43,10 @@ var temp = Object.getPrototypeOf(obj); | ||
return superclasses; | ||
} | ||
}; | ||
function jsonifyError(error) { | ||
},{}],5:[function(require,module,exports){ | ||
"use strict"; | ||
var getSuperclasses = require("./get-superclasses"); | ||
module.exports = function jsonifyError(error) { | ||
if (!(error instanceof Error)) return error; | ||
@@ -33,2 +60,3 @@ var wrappedError = {}; | ||
for (var x in error) { | ||
if (typeof error[x] === "function") continue; | ||
wrappedError.enumerableFields[x] = error[x]; | ||
@@ -44,43 +72,125 @@ } | ||
return wrappedError; | ||
} | ||
}; | ||
},{"./get-superclasses":4}],6:[function(require,module,exports){ | ||
"use strict"; | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
var toString = require("./to-string"); | ||
function mapArgs(args) { | ||
return args.map(function (arg) { | ||
return arg instanceof Error ? jsonifyError(arg) : arg; | ||
return arg instanceof Error ? toString(arg) : arg; | ||
}); | ||
} | ||
var methodNames = ["log", "debug", "info", "warn", "error"]; | ||
var alreadyOverridden = false; | ||
jsonifyError.overrideConsole = function () { | ||
module.exports = function () { | ||
if (alreadyOverridden) return; | ||
alreadyOverridden = true; | ||
var defaultConsoleLog = console.log.bind(console); | ||
var defaultConsoleWarn = console.warn.bind(console); | ||
var defaultConsoleError = console.error.bind(console); | ||
console.log = function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
defaultConsoleLog.apply(undefined, _toConsumableArray(mapArgs(args))); | ||
var originalMethods = {}; | ||
var _loop = function _loop(methodName) { | ||
if (!console[methodName]) return "continue"; | ||
originalMethods[methodName] = console[methodName].bind(console); | ||
console[methodName] = function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
originalMethods[methodName].apply(originalMethods, _toConsumableArray(mapArgs(args))); | ||
}; | ||
}; | ||
console.warn = function () { | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = methodNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var methodName = _step.value; | ||
var _ret = _loop(methodName); | ||
if (_ret === "continue") continue; | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
}; | ||
defaultConsoleWarn.apply(undefined, _toConsumableArray(mapArgs(args))); | ||
},{"./to-string":8}],7:[function(require,module,exports){ | ||
"use strict"; | ||
var jsonifyError = require("./jsonify-error"); | ||
var toString = require("./to-string"); | ||
module.exports = function () { | ||
/** | ||
* Converts this Error instance to a JSON representation. | ||
* | ||
* @return {object} | ||
*/ | ||
Error.prototype.toJSON = function () { | ||
return jsonifyError(this); | ||
}; | ||
console.error = function () { | ||
for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
defaultConsoleError.apply(undefined, _toConsumableArray(mapArgs(args))); | ||
/** | ||
* Converts this Error instance to the full stringification | ||
* of its JSON representation. | ||
* | ||
* @param {number} [amountOfSpaces=4] The amount of spaces to use | ||
* for indentation in the output string. | ||
* | ||
* @return {string} | ||
*/ | ||
Error.prototype.toString = function () { | ||
var amountOfSpaces = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 4; | ||
return toString(this, amountOfSpaces); | ||
}; | ||
}; | ||
module.exports = jsonifyError; | ||
},{"./jsonify-error":5,"./to-string":8}],8:[function(require,module,exports){ | ||
"use strict"; | ||
},{}]},{},[1]) | ||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJicm93c2VyLWVudHJ5cG9pbnQuanMiLCJpbmRleC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtBQ0FBOztBQUNBLE9BQU8sWUFBUCxHQUFzQixRQUFRLFlBQVIsQ0FBdEI7OztBQ0RBOzs7O0FBRUEsU0FBUyxlQUFULENBQXlCLEdBQXpCLEVBQThCO0FBQzFCLFFBQU0sZUFBZSxFQUFyQjtBQUNBLFFBQUksT0FBTyxPQUFPLGNBQVAsQ0FBc0IsR0FBdEIsQ0FBWDtBQUNBLFFBQUksU0FBUyxJQUFiLEVBQW1CLE9BQU8sT0FBTyxjQUFQLENBQXNCLElBQXRCLENBQVA7QUFDbkIsV0FBTyxTQUFTLElBQWhCLEVBQXNCO0FBQ2xCLHFCQUFhLElBQWIsQ0FBa0IsS0FBSyxXQUFMLENBQWlCLElBQW5DO0FBQ0EsZUFBTyxPQUFPLGNBQVAsQ0FBc0IsSUFBdEIsQ0FBUDtBQUNIO0FBQ0QsV0FBTyxZQUFQO0FBQ0g7O0FBRUQsU0FBUyxZQUFULENBQXNCLEt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ZnlFcnJvcjsiXX0= | ||
var jsonifyError = require("./jsonify-error"); | ||
/** | ||
* Converts the given error to a big string representation, containing | ||
* the whole data from its JSON representation. | ||
* | ||
* @param {error} error The error to be converted. | ||
* @param {number} [amountOfSpaces=4] The amount of spaces to use | ||
* for indentation in the output string. | ||
* | ||
* @return {string} | ||
* @throws {TypeError} If the given error is not an instance of Error | ||
*/ | ||
module.exports = function toString(error) { | ||
var amountOfSpaces = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; | ||
if (!(error instanceof Error)) throw new TypeError("jsonifyError.toString() error: First argument must be instance of Error."); | ||
var asJSON = jsonifyError(error); | ||
return asJSON.className + ": " + asJSON.message + " " + JSON.stringify(asJSON, null, amountOfSpaces); | ||
}; | ||
},{"./jsonify-error":5}]},{},[1]) | ||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJicm93c2VyLWVudHJ5cG9pbnQuanMiLCJpbmRleC5qcyIsImxpYi9icm93c2VyLXNwZWNpZmljL2xvZy5qcyIsImxpYi9nZXQtc3VwZXJjbGFzc2VzLmpzIiwibGliL2pzb25pZnktZXJyb3IuanMiLCJsaWIvb3ZlcnJpZGUtY29uc29sZS5qcyIsImxpYi9vdmVycmlkZS1lcnJvci1tZXRob2RzLmpzIiwibGliL3RvLXN0cmluZy5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtBQ0FBOztBQUNBLE9BQU8sWUFBUCxHQUFzQixRQUFRLFlBQVIsQ0FBdEI7OztBQ0RBOztBQUVBLElBQU0sZUFBZSxRQUFRLHFCQUFSLENBQXJCO0FBQ0EsSUFBTSxrQkFBa0IsUUFBUSx3QkFBUixDQUF4QjtBQUNBLElBQU0sdUJBQXVCLFFBQVEsOEJBQVIsQ0FBN0I7QUFDQSxJQUFNLE1BQU0sUUFBUSxXQU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iaWcgc3RyaW5nIHJlcHJlc2VudGF0aW9uLCBjb250YWluaW5nXHJcbiAqIHRoZSB3aG9sZSBkYXRhIGZyb20gaXRzIEpTT04gcmVwcmVzZW50YXRpb24uXHJcbiAqIFxyXG4gKiBAcGFyYW0ge2Vycm9yfSBlcnJvciBUaGUgZXJyb3IgdG8gYmUgY29udmVydGVkLlxyXG4gKiBAcGFyYW0ge251bWJlcn0gW2Ftb3VudE9mU3BhY2VzPTRdIFRoZSBhbW91bnQgb2Ygc3BhY2VzIHRvIHVzZVxyXG4gKiBmb3IgaW5kZW50YXRpb24gaW4gdGhlIG91dHB1dCBzdHJpbmcuXHJcbiAqIFxyXG4gKiBAcmV0dXJuIHtzdHJpbmd9XHJcbiAqIEB0aHJvd3Mge1R5cGVFcnJvcn0gSWYgdGhlIGdpdmVuIGVycm9yIGlzIG5vdCBhbiBpbnN0YW5jZSBvZiBFcnJvclxyXG4gKi9cclxubW9kdWxlLmV4cG9ydHMgPSBmdW5jdGlvbiB0b1N0cmluZyhlcnJvciwgYW1vdW50T2ZTcGFjZXMgPSA0KSB7XHJcbiAgICBpZiAoIShlcnJvciBpbnN0YW5jZW9mIEVycm9yKSkgdGhyb3cgbmV3IFR5cGVFcnJvcihcImpzb25pZnlFcnJvci50b1N0cmluZygpIGVycm9yOiBGaXJzdCBhcmd1bWVudCBtdXN0IGJlIGluc3RhbmNlIG9mIEVycm9yLlwiKTtcclxuICAgIGNvbnN0IGFzSlNPTiA9IGpzb25pZnlFcnJvcihlcnJvcik7XHJcbiAgICByZXR1cm4gYCR7YXNKU09OLmNsYXNzTmFtZX06ICR7YXNKU09OLm1lc3NhZ2V9ICR7SlNPTi5zdHJpbmdpZnkoYXNKU09OLCBudWxsLCBhbW91bnRPZlNwYWNlcyl9YDtcclxufTsiXX0= |
@@ -1,1 +0,1 @@ | ||
!function(){return function r(n,e,o){function t(i,s){if(!e[i]){if(!n[i]){var c="function"==typeof require&&require;if(!s&&c)return c(i,!0);if(a)return a(i,!0);var u=new Error("Cannot find module '"+i+"'");throw u.code="MODULE_NOT_FOUND",u}var l=e[i]={exports:{}};n[i][0].call(l.exports,function(r){return t(n[i][1][r]||r)},l,l.exports,r,n,e,o)}return e[i].exports}for(var a="function"==typeof require&&require,i=0;i<o.length;i++)t(o[i]);return t}}()({1:[function(r,n,e){"use strict";window.jsonifyError=r("./index.js")},{"./index.js":2}],2:[function(r,n,e){"use strict";function o(r){if(Array.isArray(r)){for(var n=0,e=Array(r.length);n<r.length;n++)e[n]=r[n];return e}return Array.from(r)}function t(r){if(!(r instanceof Error))return r;var n={};for(var e in n.name=r.name||"<no name available>",n.className=r.constructor.name||"<no class name available>",n.message=r.message||"<no message available>",n.superclasses=function(r){var n=[],e=Object.getPrototypeOf(r);for(null!==e&&(e=Object.getPrototypeOf(e));null!==e;)n.push(e.constructor.name),e=Object.getPrototypeOf(e);return n}(r),n.enumerableFields={},r)n.enumerableFields[e]=r[e];return"string"==typeof r.stack&&r.stack.length>0?n.stack=r.stack.split("\n").map(function(r){return r.replace(/^\s+/,"")}):n.stack=r.stack||"<no stack trace available>",n}function a(r){return r.map(function(r){return r instanceof Error?t(r):r})}var i=!1;t.overrideConsole=function(){if(!i){i=!0;var r=console.log.bind(console),n=console.warn.bind(console),e=console.error.bind(console);console.log=function(){for(var n=arguments.length,e=Array(n),t=0;t<n;t++)e[t]=arguments[t];r.apply(void 0,o(a(e)))},console.warn=function(){for(var r=arguments.length,e=Array(r),t=0;t<r;t++)e[t]=arguments[t];n.apply(void 0,o(a(e)))},console.error=function(){for(var r=arguments.length,n=Array(r),t=0;t<r;t++)n[t]=arguments[t];e.apply(void 0,o(a(n)))}}},n.exports=t},{}]},{},[1]); | ||
!function(){return function r(e,t,o){function n(s,a){if(!t[s]){if(!e[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(i)return i(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var f=t[s]={exports:{}};e[s][0].call(f.exports,function(r){return n(e[s][1][r]||r)},f,f.exports,r,e,t,o)}return t[s].exports}for(var i="function"==typeof require&&require,s=0;s<o.length;s++)n(o[s]);return n}}()({1:[function(r,e,t){"use strict";window.jsonifyError=r("./index.js")},{"./index.js":2}],2:[function(r,e,t){"use strict";var o=r("./lib/jsonify-error"),n=r("./lib/override-console"),i=r("./lib/override-error-methods"),s=r("./lib/log");e.exports=o,e.exports.overrideConsole=n,e.exports.overrideErrorMethods=i,e.exports.log=s},{"./lib/jsonify-error":5,"./lib/log":3,"./lib/override-console":6,"./lib/override-error-methods":7}],3:[function(r,e,t){"use strict";var o=r("./../to-string");e.exports=function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;console.error(o(r,e))}},{"./../to-string":8}],4:[function(r,e,t){"use strict";e.exports=function(r){var e=[],t=Object.getPrototypeOf(r);for(null!==t&&(t=Object.getPrototypeOf(t));null!==t;)e.push(t.constructor.name),t=Object.getPrototypeOf(t);return e}},{}],5:[function(r,e,t){"use strict";var o=r("./get-superclasses");e.exports=function(r){if(!(r instanceof Error))return r;var e={};for(var t in e.name=r.name||"<no name available>",e.className=r.constructor.name||"<no class name available>",e.message=r.message||"<no message available>",e.superclasses=o(r),e.enumerableFields={},r)"function"!=typeof r[t]&&(e.enumerableFields[t]=r[t]);return"string"==typeof r.stack&&r.stack.length>0?e.stack=r.stack.split("\n").map(function(r){return r.replace(/^\s+/,"")}):e.stack=r.stack||"<no stack trace available>",e}},{"./get-superclasses":4}],6:[function(r,e,t){"use strict";var o=r("./to-string");var n=["log","debug","info","warn","error"],i=!1;e.exports=function(){if(!i){i=!0;var r={},e=function(e){if(!console[e])return"continue";r[e]=console[e].bind(console),console[e]=function(){for(var t=arguments.length,n=Array(t),i=0;i<t;i++)n[i]=arguments[i];r[e].apply(r,function(r){if(Array.isArray(r)){for(var e=0,t=Array(r.length);e<r.length;e++)t[e]=r[e];return t}return Array.from(r)}(function(r){return r.map(function(r){return r instanceof Error?o(r):r})}(n)))}},t=!0,s=!1,a=void 0;try{for(var u,c=n[Symbol.iterator]();!(t=(u=c.next()).done);t=!0)e(u.value)}catch(r){s=!0,a=r}finally{try{!t&&c.return&&c.return()}finally{if(s)throw a}}}}},{"./to-string":8}],7:[function(r,e,t){"use strict";var o=r("./jsonify-error"),n=r("./to-string");e.exports=function(){Error.prototype.toJSON=function(){return o(this)},Error.prototype.toString=function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:4;return n(this,r)}}},{"./jsonify-error":5,"./to-string":8}],8:[function(r,e,t){"use strict";var o=r("./jsonify-error");e.exports=function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;if(!(r instanceof Error))throw new TypeError("jsonifyError.toString() error: First argument must be instance of Error.");var t=o(r);return t.className+": "+t.message+" "+JSON.stringify(t,null,e)}},{"./jsonify-error":5}]},{},[1]); |
@@ -7,3 +7,23 @@ (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
function getSuperclasses(obj) { | ||
const jsonifyError = require("./lib/jsonify-error"); | ||
const overrideConsole = require("./lib/override-console"); | ||
const overrideErrorMethods = require("./lib/override-error-methods"); | ||
const log = require("./lib/log"); | ||
module.exports = jsonifyError; | ||
module.exports.overrideConsole = overrideConsole; | ||
module.exports.overrideErrorMethods = overrideErrorMethods; | ||
module.exports.log = log; | ||
},{"./lib/jsonify-error":5,"./lib/log":3,"./lib/override-console":6,"./lib/override-error-methods":7}],3:[function(require,module,exports){ | ||
"use strict"; | ||
const toString = require("./../to-string"); | ||
module.exports = function log(error, amountOfSpaces = 4) { | ||
console.error(toString(error, amountOfSpaces)); | ||
}; | ||
},{"./../to-string":8}],4:[function(require,module,exports){ | ||
"use strict"; | ||
module.exports = function getSuperclasses(obj) { | ||
const superclasses = []; | ||
@@ -17,5 +37,9 @@ let temp = Object.getPrototypeOf(obj); | ||
return superclasses; | ||
} | ||
}; | ||
},{}],5:[function(require,module,exports){ | ||
"use strict"; | ||
function jsonifyError(error) { | ||
const getSuperclasses = require("./get-superclasses"); | ||
module.exports = function jsonifyError(error) { | ||
if (!(error instanceof Error)) return error; | ||
@@ -28,3 +52,4 @@ const wrappedError = {}; | ||
wrappedError.enumerableFields = {}; | ||
for (let x in error) { | ||
for (const x in error) { | ||
if (typeof error[x] === "function") continue; | ||
wrappedError.enumerableFields[x] = error[x]; | ||
@@ -38,28 +63,83 @@ } | ||
return wrappedError; | ||
} | ||
}; | ||
},{"./get-superclasses":4}],6:[function(require,module,exports){ | ||
"use strict"; | ||
const toString = require("./to-string"); | ||
function mapArgs(args) { | ||
return args.map(arg => arg instanceof Error ? jsonifyError(arg) : arg); | ||
return args.map(arg => arg instanceof Error ? toString(arg) : arg); | ||
} | ||
const methodNames = ["log", "debug", "info", "warn", "error"]; | ||
let alreadyOverridden = false; | ||
jsonifyError.overrideConsole = function() { | ||
module.exports = function() { | ||
if (alreadyOverridden) return; | ||
alreadyOverridden = true; | ||
const defaultConsoleLog = console.log.bind(console); | ||
const defaultConsoleWarn = console.warn.bind(console); | ||
const defaultConsoleError = console.error.bind(console); | ||
console.log = function(...args) { | ||
defaultConsoleLog(...mapArgs(args)); | ||
const originalMethods = {}; | ||
for (const methodName of methodNames) { | ||
if (!console[methodName]) continue; | ||
originalMethods[methodName] = console[methodName].bind(console); | ||
console[methodName] = function(...args) { | ||
originalMethods[methodName](...mapArgs(args)); | ||
}; | ||
} | ||
}; | ||
},{"./to-string":8}],7:[function(require,module,exports){ | ||
"use strict"; | ||
const jsonifyError = require("./jsonify-error"); | ||
const toString = require("./to-string"); | ||
module.exports = function() { | ||
/** | ||
* Converts this Error instance to a JSON representation. | ||
* | ||
* @return {object} | ||
*/ | ||
Error.prototype.toJSON = function() { | ||
return jsonifyError(this); | ||
}; | ||
console.warn = function(...args) { | ||
defaultConsoleWarn(...mapArgs(args)); | ||
/** | ||
* Converts this Error instance to the full stringification | ||
* of its JSON representation. | ||
* | ||
* @param {number} [amountOfSpaces=4] The amount of spaces to use | ||
* for indentation in the output string. | ||
* | ||
* @return {string} | ||
*/ | ||
Error.prototype.toString = function(amountOfSpaces = 4) { | ||
return toString(this, amountOfSpaces); | ||
}; | ||
console.error = function(...args) { | ||
defaultConsoleError(...mapArgs(args)); | ||
}; | ||
}; | ||
},{"./jsonify-error":5,"./to-string":8}],8:[function(require,module,exports){ | ||
"use strict"; | ||
module.exports = jsonifyError; | ||
},{}]},{},[1]) | ||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJicm93c2VyLWVudHJ5cG9pbnQuanMiLCJpbmRleC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtBQ0FBO0FBQ0E7O0FDREE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0EiLCJmaWxlIjoiZ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JncykpO1xyXG4gICAgfTtcclxuICAgIGNvbnNvbGUuZXJyb3IgPSBmdW5jdGlvbiguLi5hcmdzKSB7XHJcbiAgICAgICAgZGVmYXVsdENvbnNvbGVFcnJvciguLi5tYXBBcmdzKGFyZ3MpKTtcclxuICAgIH07XHJcbn07XHJcblxyXG5tb2R1bGUuZXhwb3J0cyA9IGpzb25pZnlFcnJvcjsiXX0= | ||
const jsonifyError = require("./jsonify-error"); | ||
/** | ||
* Converts the given error to a big string representation, containing | ||
* the whole data from its JSON representation. | ||
* | ||
* @param {error} error The error to be converted. | ||
* @param {number} [amountOfSpaces=4] The amount of spaces to use | ||
* for indentation in the output string. | ||
* | ||
* @return {string} | ||
* @throws {TypeError} If the given error is not an instance of Error | ||
*/ | ||
module.exports = function toString(error, amountOfSpaces = 4) { | ||
if (!(error instanceof Error)) throw new TypeError("jsonifyError.toString() error: First argument must be instance of Error."); | ||
const asJSON = jsonifyError(error); | ||
return `${asJSON.className}: ${asJSON.message} ${JSON.stringify(asJSON, null, amountOfSpaces)}`; | ||
}; | ||
},{"./jsonify-error":5}]},{},[1]) | ||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJicm93c2VyLWVudHJ5cG9pbnQuanMiLCJpbmRleC5qcyIsImxpYi9icm93c2VyLXNwZWNpZmljL2xvZy5qcyIsImxpYi9nZXQtc3VwZXJjbGFzc2VzLmpzIiwibGliL2pzb25pZnktZXJyb3IuanMiLCJsaWIvb3ZlcnJpZGUtY29uc29sZS5qcyIsImxpYi9vdmVycmlkZS1lcnJvci1tZXRob2RzLmpzIiwibGliL3RvLXN0cmluZy5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtBQ0FBO0FBQ0E7O0FDREE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQT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IGFtb3VudE9mU3BhY2VzKX1gO1xyXG59OyJdfQ== |
@@ -1,1 +0,1 @@ | ||
!function(){return function e(n,o,r){function t(c,a){if(!o[c]){if(!n[c]){var i="function"==typeof require&&require;if(!a&&i)return i(c,!0);if(s)return s(c,!0);var l=new Error("Cannot find module '"+c+"'");throw l.code="MODULE_NOT_FOUND",l}var u=o[c]={exports:{}};n[c][0].call(u.exports,function(e){return t(n[c][1][e]||e)},u,u.exports,e,n,o,r)}return o[c].exports}for(var s="function"==typeof require&&require,c=0;c<r.length;c++)t(r[c]);return t}}()({1:[function(e,n,o){"use strict";window.jsonifyError=e("./index.js")},{"./index.js":2}],2:[function(e,n,o){"use strict";function r(e){if(!(e instanceof Error))return e;const n={};n.name=e.name||"<no name available>",n.className=e.constructor.name||"<no class name available>",n.message=e.message||"<no message available>",n.superclasses=function(e){const n=[];let o=Object.getPrototypeOf(e);for(null!==o&&(o=Object.getPrototypeOf(o));null!==o;)n.push(o.constructor.name),o=Object.getPrototypeOf(o);return n}(e),n.enumerableFields={};for(let o in e)n.enumerableFields[o]=e[o];return"string"==typeof e.stack&&e.stack.length>0?n.stack=e.stack.split("\n").map(e=>e.replace(/^\s+/,"")):n.stack=e.stack||"<no stack trace available>",n}function t(e){return e.map(e=>e instanceof Error?r(e):e)}let s=!1;r.overrideConsole=function(){if(s)return;s=!0;const e=console.log.bind(console),n=console.warn.bind(console),o=console.error.bind(console);console.log=function(...n){e(...t(n))},console.warn=function(...e){n(...t(e))},console.error=function(...e){o(...t(e))}},n.exports=r},{}]},{},[1]); | ||
!function(){return function r(o,t,e){function n(i,c){if(!t[i]){if(!o[i]){var u="function"==typeof require&&require;if(!c&&u)return u(i,!0);if(s)return s(i,!0);var f=new Error("Cannot find module '"+i+"'");throw f.code="MODULE_NOT_FOUND",f}var a=t[i]={exports:{}};o[i][0].call(a.exports,function(r){return n(o[i][1][r]||r)},a,a.exports,r,o,t,e)}return t[i].exports}for(var s="function"==typeof require&&require,i=0;i<e.length;i++)n(e[i]);return n}}()({1:[function(r,o,t){"use strict";window.jsonifyError=r("./index.js")},{"./index.js":2}],2:[function(r,o,t){"use strict";const e=r("./lib/jsonify-error"),n=r("./lib/override-console"),s=r("./lib/override-error-methods"),i=r("./lib/log");o.exports=e,o.exports.overrideConsole=n,o.exports.overrideErrorMethods=s,o.exports.log=i},{"./lib/jsonify-error":5,"./lib/log":3,"./lib/override-console":6,"./lib/override-error-methods":7}],3:[function(r,o,t){"use strict";const e=r("./../to-string");o.exports=function(r,o=4){console.error(e(r,o))}},{"./../to-string":8}],4:[function(r,o,t){"use strict";o.exports=function(r){const o=[];let t=Object.getPrototypeOf(r);for(null!==t&&(t=Object.getPrototypeOf(t));null!==t;)o.push(t.constructor.name),t=Object.getPrototypeOf(t);return o}},{}],5:[function(r,o,t){"use strict";const e=r("./get-superclasses");o.exports=function(r){if(!(r instanceof Error))return r;const o={};o.name=r.name||"<no name available>",o.className=r.constructor.name||"<no class name available>",o.message=r.message||"<no message available>",o.superclasses=e(r),o.enumerableFields={};for(const t in r)"function"!=typeof r[t]&&(o.enumerableFields[t]=r[t]);return"string"==typeof r.stack&&r.stack.length>0?o.stack=r.stack.split("\n").map(r=>r.replace(/^\s+/,"")):o.stack=r.stack||"<no stack trace available>",o}},{"./get-superclasses":4}],6:[function(r,o,t){"use strict";const e=r("./to-string");function n(r){return r.map(r=>r instanceof Error?e(r):r)}const s=["log","debug","info","warn","error"];let i=!1;o.exports=function(){if(i)return;i=!0;const r={};for(const o of s)console[o]&&(r[o]=console[o].bind(console),console[o]=function(...t){r[o](...n(t))})}},{"./to-string":8}],7:[function(r,o,t){"use strict";const e=r("./jsonify-error"),n=r("./to-string");o.exports=function(){Error.prototype.toJSON=function(){return e(this)},Error.prototype.toString=function(r=4){return n(this,r)}}},{"./jsonify-error":5,"./to-string":8}],8:[function(r,o,t){"use strict";const e=r("./jsonify-error");o.exports=function(r,o=4){if(!(r instanceof Error))throw new TypeError("jsonifyError.toString() error: First argument must be instance of Error.");const t=e(r);return`${t.className}: ${t.message} ${JSON.stringify(t,null,o)}`}},{"./jsonify-error":5}]},{},[1]); |
60
index.js
"use strict"; | ||
function getSuperclasses(obj) { | ||
const superclasses = []; | ||
let temp = Object.getPrototypeOf(obj); | ||
if (temp !== null) temp = Object.getPrototypeOf(temp); | ||
while (temp !== null) { | ||
superclasses.push(temp.constructor.name); | ||
temp = Object.getPrototypeOf(temp); | ||
} | ||
return superclasses; | ||
} | ||
const jsonifyError = require("./lib/jsonify-error"); | ||
const overrideConsole = require("./lib/override-console"); | ||
const overrideErrorMethods = require("./lib/override-error-methods"); | ||
const log = require("./lib/log"); | ||
function jsonifyError(error) { | ||
if (!(error instanceof Error)) return error; | ||
const wrappedError = {}; | ||
wrappedError.name = error.name || "<no name available>"; | ||
wrappedError.className = error.constructor.name || "<no class name available>"; | ||
wrappedError.message = error.message || "<no message available>"; | ||
wrappedError.superclasses = getSuperclasses(error); | ||
wrappedError.enumerableFields = {}; | ||
for (let x in error) { | ||
wrappedError.enumerableFields[x] = error[x]; | ||
} | ||
if (typeof error.stack === "string" && error.stack.length > 0) { | ||
wrappedError.stack = error.stack.split('\n').map(x => x.replace(/^\s+/, "")); | ||
} else { | ||
wrappedError.stack = error.stack || "<no stack trace available>"; | ||
} | ||
return wrappedError; | ||
} | ||
function mapArgs(args) { | ||
return args.map(arg => arg instanceof Error ? jsonifyError(arg) : arg); | ||
} | ||
let alreadyOverridden = false; | ||
jsonifyError.overrideConsole = function() { | ||
if (alreadyOverridden) return; | ||
alreadyOverridden = true; | ||
const defaultConsoleLog = console.log.bind(console); | ||
const defaultConsoleWarn = console.warn.bind(console); | ||
const defaultConsoleError = console.error.bind(console); | ||
console.log = function(...args) { | ||
defaultConsoleLog(...mapArgs(args)); | ||
}; | ||
console.warn = function(...args) { | ||
defaultConsoleWarn(...mapArgs(args)); | ||
}; | ||
console.error = function(...args) { | ||
defaultConsoleError(...mapArgs(args)); | ||
}; | ||
}; | ||
module.exports = jsonifyError; | ||
module.exports = jsonifyError; | ||
module.exports.overrideConsole = overrideConsole; | ||
module.exports.overrideErrorMethods = overrideErrorMethods; | ||
module.exports.log = log; |
{ | ||
"name": "jsonify-error", | ||
"version": "1.3.1", | ||
"description": "Get a plain object fully representing the error for better logs and server responses.", | ||
"version": "1.4.0", | ||
"description": "Convert errors to JSON or to a good string. Develop faster with better error messages.", | ||
"main": "index.js", | ||
"browser": { | ||
"./lib/log.js": "./lib/browser-specific/log.js" | ||
}, | ||
"jsdelivr": "dist/jsonify-error.js", | ||
@@ -12,16 +15,19 @@ "repository": { | ||
"scripts": { | ||
"build-dev-es6-watch": "watchify browser-entrypoint.js --outfile=\"dist/jsonify-error.js\" --verbose --debug", | ||
"build-dev-es6": "browserify --debug browser-entrypoint.js -o dist/jsonify-error.js", | ||
"build-es6": "npm run build-dev-es6 && uglifyjs dist/jsonify-error.js --compress --mangle --source-map -o dist/jsonify-error.min.js", | ||
"build-dev-es5": "browserify --debug browser-entrypoint.js -o dist/jsonify-error.es5.js -t [ babelify --presets [ \"babel-preset-env\" ] ]", | ||
"build-es5": "npm run build-dev-es5 && uglifyjs dist/jsonify-error.es5.js --compress --mangle --source-map -o dist/jsonify-error.es5.min.js", | ||
"build": "npm run build-es6 && npm run build-es5 && npm run crlf", | ||
"crlf": "node helpers/ensure-crlf.js", | ||
"sri": "node helpers/sri-sha384.js", | ||
"lint": "eslint ." | ||
"build:es6": "browserify --debug browser-entrypoint.js -o dist/jsonify-error.js", | ||
"build:es6-min": "uglifyjs dist/jsonify-error.js --compress --mangle --source-map -o dist/jsonify-error.min.js", | ||
"build:es5": "browserify --debug browser-entrypoint.js -o dist/jsonify-error.es5.js -t [ babelify --presets [ \"babel-preset-env\" ] ]", | ||
"build:es5-min": "uglifyjs dist/jsonify-error.es5.js --compress --mangle --source-map -o dist/jsonify-error.es5.min.js", | ||
"build:crlf": "node helpers/ensure-crlf.js", | ||
"build": "run-s build:*", | ||
"test": "run-s build test:*", | ||
"test:lint": "eslint .", | ||
"test:node": "nyc --all --reporter=text --reporter=text-summary --reporter=html mocha \"test/node/**/*.js\"", | ||
"test:browser": "karma start", | ||
"sri": "node helpers/sri-sha384.js" | ||
}, | ||
"files": [ | ||
"browser-entrypoint.js", | ||
"dist", | ||
"index.js", | ||
"browser-entrypoint.js" | ||
"lib" | ||
], | ||
@@ -41,15 +47,36 @@ "keywords": [ | ||
"babel-core": "^6.26.3", | ||
"babel-polyfill": "^6.26.0", | ||
"babel-preset-env": "^1.7.0", | ||
"babelify": "^8.0.0", | ||
"browserify": "^16.2.2", | ||
"browserify-istanbul": "^3.0.1", | ||
"chai": "^4.1.2", | ||
"eslint": "^5.2.0", | ||
"eslint-plugin-mocha": "^5.1.0", | ||
"eslint-plugin-node": "^8.0.0", | ||
"fs-jetpack": "^2.1.0", | ||
"karma": "^3.0.0", | ||
"karma-babel-preprocessor": "^7.0.0", | ||
"karma-browserify": "^5.3.0", | ||
"karma-chai": "^0.1.0", | ||
"karma-chrome-launcher": "^2.2.0", | ||
"karma-coverage": "^1.1.2", | ||
"karma-mocha": "^1.3.0", | ||
"mocha": "^5.2.0", | ||
"npm-run-all": "^4.1.3", | ||
"nyc": "^13.1.0", | ||
"puppeteer": "^1.7.0", | ||
"sha.js": "^2.4.11", | ||
"uglify-es": "^3.3.9", | ||
"watchify": "^3.11.0" | ||
"uglify-es": "^3.3.9" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/papb/jsonify-error/issues" | ||
}, | ||
"homepage": "https://github.com/papb/jsonify-error#readme" | ||
"homepage": "https://github.com/papb/jsonify-error#readme", | ||
"dependencies": { | ||
"chalk": "^2.4.1" | ||
} | ||
} |
@@ -7,2 +7,3 @@ jsonify-error | ||
[![NPM version][npm-version-badge]][npm-url] | ||
[![Build status][build-status-badge]][travis-url] | ||
[![License][license-badge]][license-url] | ||
@@ -17,6 +18,18 @@ [![NPM downloads][npm-downloads-badge]][npm-url] | ||
It's 2018 and neither `JSON.stringify(e)` nor `console.log(e)` behave as nicely as they could when `e` is an error. | ||
Convert errors to JSON or to a good string. Develop faster with better error messages. | ||
With **jsonify-error**, use `jsonifyError(e)` instead of `e`. It produces a plain object with everything one could wish to see about an error. | ||
It's 2018 and still the default behavior of JavaScript could be better with regard to displaying errors: | ||
* `console.log(e)`: Bad | ||
* `JSON.stringify(e)`: Bad | ||
* `e.toString()`: Bad | ||
* `e.toJSON()`: Doesn't exist | ||
But **jsonify-error** comes to the rescue: | ||
* For `console.log(e)`: Use `jsonifyError.log(e)` instead (or call `jsonifyError.overrideConsole()` once and then `console.log(e)` will work too). | ||
* For `JSON.stringify(e)`: Use `JSON.stringify(jsonifyError(e))` instead (or call `jsonifyError.overrideErrorMethods()` once and then of `JSON.stringify(e)` will work too). | ||
* For `e.toString()`: Call `jsonifyError.overrideErrorMethods()` once and `e.toString()` will work. | ||
* For `e.toJSON()`: Use `jsonifyError(e)` instead (or call `jsonifyError.overrideErrorMethods()` once and `e.toJSON()` will work). | ||
# Installation | ||
@@ -39,2 +52,4 @@ | ||
Or if you're developing a browser library with Browserify, you can just `require("jsonify-error")` normally. | ||
## In Node | ||
@@ -48,5 +63,5 @@ | ||
# Example result | ||
# What it does | ||
The resulting plain object has the form: | ||
The main purpose of **jsonify-error**, as the name suggests, is to convert an error to a plain object. Just do `jsonifyError(e)` and you will get something like: | ||
@@ -79,6 +94,13 @@ ```javascript | ||
# Example usage: try-catch | ||
If you're thinking *"Great! Now I can do `console.log(jsonifyError(e))` instead of `console.log(e)`"*, you're in the right track, but you can do even better! | ||
A few utility methods are exposed by **jsonifyError** beyond the main one, as mentioned in the beginning of this README. | ||
* `jsonifyError.log(e)`: Logs the error in a much better way than `console.log(e)`. | ||
* `jsonifyError.overrideConsole()`: Makes `console.log`, `console.warn`, `console.error` work like `jsonifyError.log` automatically. Calling this once is enough. | ||
* `jsonifyError.overrideErrorMethods()`: Heavily improves `e.toString()` and adds `e.toJSON()` to all errors automatically. Calling this once is enough. | ||
## Example: with try-catch blocks | ||
```javascript | ||
var jsonifyError = require("jsonify-error"); | ||
const jsonifyError = require("jsonify-error"); | ||
@@ -88,3 +110,3 @@ try { | ||
} catch (e) { | ||
console.error(jsonifyError(e)); | ||
jsonifyError.log(e); | ||
process.exit(1); | ||
@@ -94,6 +116,4 @@ } | ||
# Example usage: promises | ||
## Example: with promises | ||
For better error logs of unhandled errors in promises, the recommended solution is to **use the sibling module, [better-promise-error-log][better-promise-error-log]**. But if you insist, you can do: | ||
```javascript | ||
@@ -105,3 +125,3 @@ var jsonifyError = require("jsonify-error"); | ||
}).catch(error => { | ||
console.error(jsonifyError(e)); | ||
jsonifyError.log(e); | ||
// process.exit(1); // Exiting or not depends on your situation | ||
@@ -111,4 +131,6 @@ }); | ||
# Example usage: with express | ||
Also, for promises, there is a sibling module called **[better-promise-error-log][better-promise-error-log]** which takes care of showing the improved logs automatically for unhandled rejections. | ||
## Example: with express | ||
```javascript | ||
@@ -124,14 +146,12 @@ var jsonifyError = require("jsonify-error"); | ||
# Example usage: overriding console | ||
## Example usage: overriding methods | ||
```javascript | ||
require("jsonify-error").overrideConsole(); | ||
// Now console.log, console.warn and console.error automatically | ||
// call jsonifyError() on each argument that is instanceof Error | ||
// before logging. Note that overriding native functions/objects | ||
// is usually not a good practice so use this with caution. | ||
const jsonifyError = require("jsonify-error"); | ||
jsonifyError.overrideConsole(); | ||
jsonifyError.overrideErrorMethods(); | ||
// Now `console.log`, `console.warn` and `console.error` will be much better. | ||
// Also, `e.toString()` will be much better and `e.toJSON()` will be available. | ||
``` | ||
*Note:* since 1.2.0, you can simply `console.log(jsonifyError(anything))` if you prefer, because if `anything` is not an error, `jsonifyError` will not touch it at all. | ||
# Contributing | ||
@@ -151,2 +171,3 @@ | ||
[npm-version-badge]: https://badgen.net/npm/v/jsonify-error | ||
[build-status-badge]: https://badgen.net/travis/papb/papb-js-snippets | ||
[dependency-status-badge]: https://badgen.net/david/dep/papb/jsonify-error | ||
@@ -162,2 +183,3 @@ [dev-dependency-status-badge]: https://badgen.net/david/dev/papb/jsonify-error | ||
[license-url]: LICENSE | ||
[travis-url]: https://travis-ci.com/papb/jsonify-error | ||
[better-promise-error-log]: https://npmjs.org/package/better-promise-error-log |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63392
19
458
173
1
24
1
+ Addedchalk@^2.4.1
+ Addedansi-styles@3.2.1(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)