UNPKG

express-rendertype

Version:

Express middleware to (automatically) render content and errors to content-type

132 lines (114 loc) 3.52 kB
// Generated by IcedCoffeeScript 108.0.11 var Fancy, errify, fs, iced, path, pug, template, util, __iced_k, __iced_k_noop; iced = require('iced-runtime'); __iced_k = __iced_k_noop = function() {}; fs = require("fs"); path = require("path"); util = require("util"); pug = require("pug"); errify = require("errify"); template = fs.readFileSync(path.join(__dirname, "..", "templates", "error.pug"), "utf-8"); template = pug.compile(template); Fancy = (function() { function Fancy() {} Fancy.stringify = function(obj) { var stack, str; stack = obj.stack; if (stack) { return String(stack); } str = String(obj); if (str === Object.prototype.toString.call(obj)) { return util.inspect(obj); } else { return str; } }; Fancy.log = function(logger) { return function(err) { return setImmediate(logger, err, Fancy.stringify(err)); }; }; Fancy.html = function(err, cb) { var col, end, excerpt, file, ideally, line, name, result, row, stack, start, _, ___iced_passed_deferral, __iced_deferrals, __iced_k; __iced_k = __iced_k_noop; ___iced_passed_deferral = iced.findDeferral(arguments); ideally = errify(cb); stack = this.stringify(err); (function(_this) { return (function(__iced_k) { var _ref; if (err instanceof Error) { _ref = err.stack.split("\n"), _ = _ref[0], line = _ref[1]; result = /at\s(.+\s)?\(?(.+)\:([0-9]+)\:([0-9]+)/.exec(line); (function(__iced_k) { if (result) { name = result[2]; row = +result[3]; col = +result[4]; (function(__iced_k) { __iced_deferrals = new iced.Deferrals(__iced_k, { parent: ___iced_passed_deferral, filename: "/home/charles/source/express-rendertype/src/fancy.coffee", funcname: "Fancy.html" }); fs.readFile(name, "utf-8", ideally(__iced_deferrals.defer({ assign_fn: (function() { return function() { return file = arguments[0]; }; })(), lineno: 33 }))); __iced_deferrals._fulfill(); })(function() { file = file.split("\n"); start = row - 6 < 0 ? 0 : row - 6; end = row + 6; return __iced_k(excerpt = file.slice(start, +end + 1 || 9e9)); }); } else { return __iced_k(); } })(__iced_k); } else { return __iced_k(); } }); })(this)((function(_this) { return function() { if (!name) { err = new Error(err); row = col = start = 0; excerpt = stack && (stack.split("\n")) || []; stack = err.stack; } return cb(null, template({ name: err.name, message: err.message, line: row, column: col, excerpt: excerpt, excerpt_start: start + 1, stack: stack })); }; })(this)); }; Fancy.json = function(err) { var error, prop; error = { message: err.message, stack: err.stack }; for (prop in err) { error[prop] = err[prop]; } return { error: error }; }; return Fancy; })(); module.exports = Fancy; //# sourceMappingURL=fancy.js.map