UNPKG

893 BJavaScriptView Raw
1/** Copyright (c) 2018 Uber Technologies, Inc.
2 *
3 * This source code is licensed under the MIT license found in the
4 * LICENSE file in the root directory of this source tree.
5 *
6 * @flow
7 */
8
9/* eslint-env node */
10
11function 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
36module.exports.renderError = renderError;