From 03b54f94d42881b79c9e0799f740efe022ab0b22 Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Fri, 1 Sep 2023 11:04:04 +0200 Subject: [PATCH] Fix callServerError --- svr.js | 116 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 79 insertions(+), 37 deletions(-) diff --git a/svr.js b/svr.js index c1f967f..8098d42 100644 --- a/svr.js +++ b/svr.js @@ -2224,9 +2224,30 @@ if (!cluster.isPrimary) { function medCallback(p) { if(p) callback(p); else { - fs.access(page404, fs.constants.F_OK, function(err) { - if(err) { - fs.access("." + errorCode.toString(), fs.constants.F_OK, function(err) { + if(errorCode == 404) { + fs.access(page404, fs.constants.F_OK, function(err) { + if(err) { + fs.access("." + errorCode.toString(), fs.constants.F_OK, function(err) { + try { + if(err) { + callback(errorCode.toString() + ".html"); + } else { + callback("." + errorCode.toString()); + } + } catch(err2) { + callServerError(500, undefined, generateErrorStack(err2)); + } + }); + } else { + try { + callback(page404); + } catch(err2) { + callServerError(500, undefined, generateErrorStack(err2)); + } + } + }); + } else { + fs.access("." + errorCode.toString(), fs.constants.F_OK, function(err) { try { if(err) { callback(errorCode.toString() + ".html"); @@ -2237,14 +2258,7 @@ if (!cluster.isPrimary) { callServerError(500, undefined, generateErrorStack(err2)); } }); - } else { - try { - callback(page404); - } catch(err2) { - callServerError(500, undefined, generateErrorStack(err2)); - } - } - }); + } } } @@ -2670,27 +2684,41 @@ if (!cluster.isPrimary) { function medCallback(p) { if(p) callback(p); else { - fs.access(page404, fs.constants.F_OK, function(err) { - if(err) { - fs.access("." + errorCode.toString(), fs.constants.F_OK, function(err) { - try { - if(err) { - callback(errorCode.toString() + ".html"); - } else { - callback("." + errorCode.toString()); + if(errorCode == 404) { + fs.access(page404, fs.constants.F_OK, function(err) { + if(err) { + fs.access("." + errorCode.toString(), fs.constants.F_OK, function(err) { + try { + if(err) { + callback(errorCode.toString() + ".html"); + } else { + callback("." + errorCode.toString()); + } + } catch(err2) { + callServerError(500, undefined, generateErrorStack(err2)); } + }); + } else { + try { + callback(page404); } catch(err2) { callServerError(500, undefined, generateErrorStack(err2)); } - }); - } else { + } + }); + } else { + fs.access("." + errorCode.toString(), fs.constants.F_OK, function(err) { try { - callback(page404); + if(err) { + callback(errorCode.toString() + ".html"); + } else { + callback("." + errorCode.toString()); + } } catch(err2) { callServerError(500, undefined, generateErrorStack(err2)); } - } - }); + }); + } } } @@ -3411,27 +3439,41 @@ if (!cluster.isPrimary) { function medCallback(p) { if(p) callback(p); else { - fs.access(page404, fs.constants.F_OK, function(err) { - if(err) { - fs.access("." + errorCode.toString(), fs.constants.F_OK, function(err) { - try { - if(err) { - callback(errorCode.toString() + ".html"); - } else { - callback("." + errorCode.toString()); + if(errorCode == 404) { + fs.access(page404, fs.constants.F_OK, function(err) { + if(err) { + fs.access("." + errorCode.toString(), fs.constants.F_OK, function(err) { + try { + if(err) { + callback(errorCode.toString() + ".html"); + } else { + callback("." + errorCode.toString()); + } + } catch(err2) { + callServerError(500, undefined, generateErrorStack(err2)); } + }); + } else { + try { + callback(page404); } catch(err2) { callServerError(500, undefined, generateErrorStack(err2)); } - }); - } else { + } + }); + } else { + fs.access("." + errorCode.toString(), fs.constants.F_OK, function(err) { try { - callback(page404); + if(err) { + callback(errorCode.toString() + ".html"); + } else { + callback("." + errorCode.toString()); + } } catch(err2) { callServerError(500, undefined, generateErrorStack(err2)); } - } - }); + }); + } } }