1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | function renderError(error /*: any */ = {}) {
|
12 | let displayError;
|
13 | if (error instanceof Error) {
|
14 | displayError = error;
|
15 | } else if (typeof error === 'string') {
|
16 | displayError = new Error(error);
|
17 | } else {
|
18 | displayError = new Error(error.message);
|
19 | displayError.stack = error.stack;
|
20 | displayError.name = error.name;
|
21 | }
|
22 | return `
|
23 | <!DOCTYPE html>
|
24 | <html>
|
25 | <head>
|
26 | <title>Server error</title>
|
27 | <style>html {background:red;color:white;line-height:2;}</style>
|
28 | </head>
|
29 | <body>
|
30 | <pre>${(displayError.stack || '').replace(/\[\d\dm/gm, '')}</pre>
|
31 | </body>
|
32 | </html>
|
33 | `;
|
34 | }
|
35 |
|
36 | module.exports.renderError = renderError;
|