custom.js 589 B

1234567891011121314151617181920
  1. "use strict";
  2. var assign = require("../object/assign")
  3. , isObject = require("../object/is-object")
  4. , isValue = require("../object/is-value")
  5. , captureStackTrace = Error.captureStackTrace;
  6. module.exports = function (message/*, code, ext*/) {
  7. var err = new Error(message), code = arguments[1], ext = arguments[2];
  8. if (!isValue(ext)) {
  9. if (isObject(code)) {
  10. ext = code;
  11. code = null;
  12. }
  13. }
  14. if (isValue(ext)) assign(err, ext);
  15. if (isValue(code)) err.code = code;
  16. if (captureStackTrace) captureStackTrace(err, module.exports);
  17. return err;
  18. };