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C9B,EAAI,OAAO,GAAQ,EAAK,QAAQ,KAAK,EACtC,EACA,GACD,CAED","file":"/npm/express-status-error@0.0.3/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/express-status-error@0.0.3/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n *\n * Express 4.0 Error Handling\n *\n * To use:\n *\n * var app          = require('express')(),\n *     statusError  = require('express-status-error');\n *\n * app.use(statusError({debug:true}));\n *\n *         - then -\n *\n * if(err) res.sendError(err, 500);\n *\n *          - or -\n *\n * if(condition) res.sendError(new Error('Not Allowed'), 401);\n *\n */\n\nvar codes = require('status-codes');\n\nfunction JSONifyStack(stack){\n\tif(typeof stack != 'string') return {};\n\tvar json = {};\n\tstack.split('\\n').forEach(function(call, i){\n\t\tif(i == 0) call = call.replace('Error: ', '');\n\t\tjson[i] = call;\n\t});\n\treturn json;\n}\n\n\nmodule.exports = function statusError(params) {\n\n\tvar options = params || { log: true, debug: app.get('env') == 'development' };\n\n\t// Add method to error to jsonify it for error handling\n\tError.prototype.toJSON = function (code) {\n\n\t\tvar json = {};\n\n\t\tObject.getOwnPropertyNames(this).forEach(function (key) {\n\t\t\tif (key == 'arguments') return false;\n\t\t\tif ((process.env !== 'development' || !options.debug) && (key == 'stack' || key == 'fileName' || key == 'lineNumber')) return false;\n\t\t\tjson[key] = this[key];\n\t\t}, this);\n\n\t\tjson.status = json.status || code || 500;\n\t\tjson.name = json.name || codes[json.status || 500].name;\n\t\tjson.message = json.message || codes[json.status || 500].message;\n\n\t\treturn json;\n\n\t};\n\n\t// Expose SendError in Response object\n\treturn function statusError(req, res, next) {\n\t\tres.sendError = function (err /* Error */, code) {\n\t\t\tvar json = err instanceof Error ? err.toJSON(code) : {\n\t\t\t\tstatus: code || 500,\n\t\t\t\tname: codes[code || 500].name,\n\t\t\t\tmessage: err\n\t\t\t};\n\t\t\tif (options.debug && json.status == 500) json.error = JSONifyStack(err.stack);\n\t\t\tif (options.log) {\n\t\t\t\tif(json.status == 500){\n\t\t\t\t\tconsole.error(json.status + ' ' + json.message + '\\n' + err.stack);\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log(json.status + ' ' + json.message);\n\t\t\t\t}\n\t\t\t}\n\t\t\tres.setHeader('Content-Type', 'application/json');\n\t\t\tres.status(code || json.status).json(json);\n\t\t};\n\t\tnext();\n\t}\n\n};\n"]}