33 lines
730 B
JavaScript
33 lines
730 B
JavaScript
'use strict';
|
|
|
|
function getRespBody(err, debug) {
|
|
if (debug) {
|
|
return err.toString();
|
|
}
|
|
|
|
if (err.code === 'ECONNREFUSED') {
|
|
return 'The connection was refused. Most likely the service being connected to '
|
|
+ 'has stopped running or the configuration is wrong.';
|
|
}
|
|
|
|
return 'Bad Gateway: ' + err.code;
|
|
}
|
|
|
|
function sendBadGateway(conn, err, debug) {
|
|
var body = getRespBody(err, debug);
|
|
|
|
conn.write([
|
|
'HTTP/1.1 502 Bad Gateway'
|
|
, 'Date: ' + (new Date()).toUTCString()
|
|
, 'Connection: close'
|
|
, 'Content-Type: text/html'
|
|
, 'Content-Length: ' + body.length
|
|
, ''
|
|
, body
|
|
].join('\r\n'));
|
|
conn.end();
|
|
}
|
|
|
|
module.exports.getRespBody = getRespBody;
|
|
module.exports.sendBadGateway = sendBadGateway;
|