UNPKG

mongoose-bread

Version:

A pagination and softdelete library for mongoose

71 lines (70 loc) 2.03 kB
"use strict"; function ownKeys(a, b) { var c = Object.keys(a); if (Object.getOwnPropertySymbols) { var d = Object.getOwnPropertySymbols(a); b && (d = d.filter(function (b) { return Object.getOwnPropertyDescriptor(a, b).enumerable; })), c.push.apply(c, d); } return c; } function _objectSpread(a) { for (var b, c = 1; c < arguments.length; c++) (b = null == arguments[c] ? {} : arguments[c]), c % 2 ? ownKeys(Object(b), !0).forEach(function (c) { _defineProperty(a, c, b[c]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(a, Object.getOwnPropertyDescriptors(b)) : ownKeys(Object(b)).forEach(function (c) { Object.defineProperty(a, c, Object.getOwnPropertyDescriptor(b, c)); }); return a; } function _defineProperty(a, b, c) { return ( (b = _toPropertyKey(b)), b in a ? Object.defineProperty(a, b, { value: c, enumerable: !0, configurable: !0, writable: !0, }) : (a[b] = c), a ); } function _toPropertyKey(a) { var b = _toPrimitive(a, "string"); return "symbol" == typeof b ? b : b + ""; } function _toPrimitive(a, b) { if ("object" != typeof a || null === a) return a; var c = a[Symbol.toPrimitive]; if (c !== void 0) { var d = c.call(a, b || "default"); if ("object" != typeof d) return d; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === b ? String : Number)(a); } var MongooseBreadError = require("../MongooseBreadError"); function toBreadErrorFactory() { var a = 0 < arguments.length && arguments[0] !== void 0 ? arguments[0] : {}; return function (b) { if (b.message.startsWith("No document found")) throw new MongooseBreadError({ message: "Not Found", details: b.message, statusCode: 404, result: _objectSpread({}, a), }); throw b; }; } module.exports = toBreadErrorFactory;