This repository was archived by the owner on Aug 14, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
75 lines (68 loc) · 1.98 KB
/
Copy pathindex.js
File metadata and controls
75 lines (68 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
'use strict';
var stackman = require('stackman');
var multiline = require('multiline');
var hogan = require('hogan.js');
var context = hogan.compile(multiline(function(){/*
<li class="source">
<pre class="prettyprint lang-javascipt linenums:{{start}}">
{{pre}}
{{line}}
{{post}}
</pre>
</li>
*/}));
var page = hogan.compile(multiline(function(){/*
<!doctype html>
<html>
<head>
<title>Error</title>
<link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/floatdrop/express-stackman/master/css/index.css">
</head>
<body>
<h1>Error</h1>
<h2><i>{{status}}</i> — {{message}}</h2>
<ul id="stacktrace">
{{#frames}}
<li>{{filename}}:{{line}}:{{column}}</li>
{{{context}}}
{{/frames}}
</ul>
</body>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/floatdrop/express-stackman/master/css/prettify.css">
</html>
*/}));
function getContext(frame) {
return {
start: frame.getLineNumber() - (frame.context.pre || []).length,
pre: frame.context.pre.join('\n'),
line: frame.context.line,
post: frame.context.post.join('\n')
};
}
function getFrame(frame) {
return {
filename: frame.getRelativeFileName(),
line: frame.getLineNumber(),
column: frame.getColumnNumber(),
context: frame.context ? context.render(getContext(frame)) : ''
};
}
function prepeare(stack) {
return {
frames: stack.frames.map(getFrame)
};
}
module.exports = function (options) {
var parse = stackman(options);
return function (err, req, res, next) {
parse(err, function (stack) {
stack = prepeare(stack);
stack.message = err.message || err.toString();
stack.status = err.status || 500;
res
.status(stack.status)
.send(page.render(stack));
});
};
};