Add friendlier HTTP error messages
This commit is contained in:
@@ -485,7 +485,26 @@ async function doHTTPProxy(socket, request_headers) {
|
||||
var data_hex = Buffer.concat(data).toString('hex');
|
||||
|
||||
console.log(` * Proxy Request ${request_type.toUpperCase()} ${res.statusCode} for ${request_headers.request}`)
|
||||
// an http response error is not a request error, and will come here under the 'end' event rather than an 'error' event.
|
||||
switch (res.statusCode) {
|
||||
case 404:
|
||||
res.headers.http_response = res.statusCode + " The publisher can’t find the page requested.";
|
||||
break;
|
||||
|
||||
case 401:
|
||||
case 403:
|
||||
res.headers.http_response = res.statusCode + " The publisher of that page has not authorized you to use it.";
|
||||
break;
|
||||
|
||||
case 500:
|
||||
res.headers.http_response = res.statusCode + " The publisher of that page can’t be reached.";
|
||||
break;
|
||||
|
||||
default:
|
||||
res.headers.http_response = res.statusCode + " " + res.statusMessage;
|
||||
break;
|
||||
}
|
||||
|
||||
// header pass-through whitelist, case insensitive comparsion to server, however, you should
|
||||
// specify the header case as you intend for the client
|
||||
var headers = stripHeaders(res.headers, [
|
||||
@@ -509,9 +528,11 @@ async function doHTTPProxy(socket, request_headers) {
|
||||
sendToClient(socket, headers, Buffer.from(data_hex, 'hex'));
|
||||
});
|
||||
}).on('error', function (err) {
|
||||
// severe errors, such as unable to connect.
|
||||
var errpage, headers, data = null;
|
||||
if (err.code == "ENOTFOUND") errpage = wtvshared.doErrorPage(400, `The publisher ${request_data.host} is unknown.`);
|
||||
else if (err.message.indexOf("HostUnreachable") > 0) errpage = wtvshared.doErrorPage(400, `The publisher ${request_data.host} could not be reached.`);
|
||||
if (err.code == "ENOTFOUND" || err.message.indexOf("HostUnreachable") > 0) {
|
||||
errpage = wtvshared.doErrorPage(400, `The publisher <b>${request_data.host}</b> is unknown.`);
|
||||
}
|
||||
else {
|
||||
console.log(" * Unhandled Proxy Request Error:", err);
|
||||
errpage = wtvshared.doErrorPage(400);
|
||||
|
||||
Reference in New Issue
Block a user