allow error messages to be customized via config

This commit is contained in:
zefie
2022-10-15 16:23:01 -04:00
parent 130a1e3ef5
commit f36733e9c1
3 changed files with 39 additions and 5 deletions

View File

@@ -675,34 +675,36 @@ class WTVShared {
doErrorPage(code, data = null, details = null, pc_mode = false) { doErrorPage(code, data = null, details = null, pc_mode = false) {
var headers = null; var headers = null;
var minisrv_config = this.minisrv_config;
switch (code) { switch (code) {
case 401: case 401:
if (data === null) data = "Authorization Required."; if (data === null) data = minisrv_config.config.errorMessages[code].replace(/\$\{(.+)\}/g, function (x) { return minisrv_config.config[x.replace("${", '').replace('}', '')] });
if (pc_mode) headers = "401 Unauthorized\n"; if (pc_mode) headers = "401 Unauthorized\n";
else headers = code + " " + data + "\n"; else headers = code + " " + data + "\n";
headers += "Content-Type: text/html\n"; headers += "Content-Type: text/html\n";
break; break;
case 403: case 403:
if (data === null) data = "The publisher of that page has not authorized you to view it."; if (data === null) data = minisrv_config.config.errorMessages[code].replace(/\$\{(.+)\}/g, function (x) { return minisrv_config.config[x.replace("${", '').replace('}', '')] });
if (pc_mode) headers = "403 Forbidden\n"; if (pc_mode) headers = "403 Forbidden\n";
else headers = code + " " + data + "\n"; else headers = code + " " + data + "\n";
headers += "Content-Type: text/html\n"; headers += "Content-Type: text/html\n";
break; break;
case 404: case 404:
if (data === null) data = "The service could not find the requested page."; if (data === null) data = minisrv_config.config.errorMessages[code].replace(/\$\{(.+)\}/g, function (x) { return minisrv_config.config[x.replace("${", '').replace('}', '')] });
if (pc_mode) headers = "404 Not Found\n"; if (pc_mode) headers = "404 Not Found\n";
else headers = code + " " + data + "\n"; else headers = code + " " + data + "\n";
headers += "Content-Type: text/html\n"; headers += "Content-Type: text/html\n";
break; break;
case 400: case 400:
case 500: case 500:
if (data === null) data = this.minisrv_config.config.service_name + " ran into a technical problem."; if (data === null) data = minisrv_config.config.errorMessages[code].replace(/\$\{(.+)\}/g, function (x) { console.log(x); return minisrv_config.config[x.replace("${", '').replace('}', '')] });
if (details) data += "<br>Details:<br>" + details; if (details) data += "<br>Details:<br>" + details;
if (pc_mode) headers = "500 Internal Server Error\n"; if (pc_mode) headers = "500 Internal Server Error\n";
else headers = code + " " + data + "\n"; else headers = code + " " + data + "\n";
headers += "Content-Type: text/html\n"; headers += "Content-Type: text/html\n";
break; break;
default: default:
if (data === null && this.minisrv_config.config.errorMessages[code]) data = minisrv_config.config.errorMessages[code].replace(/\$\{(.+)\}/g, function (x) { return minisrv_config.config[x.replace("${",'').replace('}','')] });
headers = code + " " + data + "\n"; headers = code + " " + data + "\n";
headers += "Content-Type: text/html\n"; headers += "Content-Type: text/html\n";
break; break;

View File

@@ -48,6 +48,13 @@
"max_length": 32, "max_length": 32,
"form_size": 16 "form_size": 16
}, },
"errorMessages": {
"400": "${service_name} ran into a technical problem. Please try again.",
"401": "Authorization Required.",
"403": "The publisher of that page has not authorized you to view it.",
"404": "The service could not find the requested page.",
"500": "${service_name} ran into a technical problem. Please try again."
},
"lockdownWhitelist": [ "lockdownWhitelist": [
"wtv-1800:/preregister", "wtv-1800:/preregister",
"wtv-head-waiter:/login", "wtv-head-waiter:/login",

View File

@@ -26,7 +26,32 @@
] ]
}, },
"hide_ssid_in_logs": true, "hide_ssid_in_logs": true,
"verbosity": 2 "verbosity": 2,
"errorMessages": {
"999": "My Custom Error Code Message",
"400": "${service_name} ran into a technical problem. Please try again.",
"401": "Authorization Required.",
"403": "The publisher of that page has not authorized you to view it.",
"404": "The service could not find the requested page.",
"500": "${service_name} ran into a technical problem. Please try again."
},
"lockdownWhitelist": [
"wtv-1800:/preregister",
"wtv-head-waiter:/login",
"wtv-head-waiter:/ValidateLogin",
"wtv-head-waiter:/login-stage-two",
"wtv-head-waiter:/relogin",
"wtv-head-waiter:/ROMCache/Spacer.gif",
"wtv-head-waiter:/ROMCache/NameStrip.gif",
"wtv-head-waiter:/images/PasswordBanner.gif",
"wtv-head-waiter:/ROMCache/UtilityBullet.gif",
"wtv-head-waiter:/images/NameBanner.gif",
"wtv-head-waiter:/bad-disk",
"wtv-head-waiter:/images/signin_new_mail.gif",
"wtv-head-waiter:/images/signin_no_mail.gif",
"wtv-log:/log",
"wtv-custom-service:/my-cool-page-everyone-should-have-access-to"
]
}, },
"services": { "services": {
"wtv-1800": { "wtv-1800": {