Improved exception handling, started work on improving error messages for IP bans
This commit is contained in:
parent
7d3c31f0aa
commit
853f67fe15
15 changed files with 118 additions and 77 deletions
|
|
@ -17,7 +17,20 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
|||
//Config
|
||||
const config = require('../../config.json');
|
||||
|
||||
//At some point this will be a bit more advanced, right now it's just a placeholder :P
|
||||
module.exports.exceptionSmith = function(msg, type){
|
||||
//Create the new error with the given message
|
||||
const exception = new Error(msg);
|
||||
|
||||
//Set the error type
|
||||
exception.type = type;
|
||||
|
||||
//Mark the error as a custom error
|
||||
exception.custom = true;
|
||||
|
||||
//Return the error
|
||||
return exception;
|
||||
}
|
||||
|
||||
module.exports.errorHandler = function(res, msg, type = "Generic", status = 400){
|
||||
//Some controllers do things after sending headers, for those, we should remain silent
|
||||
if(!res.headersSent){
|
||||
|
|
@ -35,11 +48,16 @@ module.exports.localExceptionHandler = function(err){
|
|||
}
|
||||
|
||||
module.exports.exceptionHandler = function(res, err){
|
||||
//Locally handle the exception
|
||||
module.exports.localExceptionHandler(err);
|
||||
//If this is a self-made problem
|
||||
if(err.custom){
|
||||
module.exports.errorHandler(res, err.message, err.type);
|
||||
}else{
|
||||
//Locally handle the exception
|
||||
module.exports.localExceptionHandler(err);
|
||||
|
||||
//if not yell at the browser for fucking up, and tell it what it did wrong.
|
||||
module.exports.errorHandler(res, err.message, "Caught Exception");
|
||||
//if not yell at the browser for fucking up, and tell it what it did wrong.
|
||||
module.exports.errorHandler(res, "An unexpected server crash was just prevented. You should probably report this to an admin.", "Caught Exception");
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.socketErrorHandler = function(socket, msg, type = "Generic"){
|
||||
|
|
@ -47,16 +65,28 @@ module.exports.socketErrorHandler = function(socket, msg, type = "Generic"){
|
|||
}
|
||||
|
||||
module.exports.socketExceptionHandler = function(socket, err){
|
||||
//Locally handle the exception
|
||||
module.exports.localExceptionHandler(err);
|
||||
//If this is a self made problem
|
||||
if(err.custom){
|
||||
//at the browser for fucking up, and tell it what it did wrong.
|
||||
return module.exports.socketErrorHandler(socket, err.message, err.type);
|
||||
}else{
|
||||
//Locally handle the exception
|
||||
module.exports.localExceptionHandler(err);
|
||||
|
||||
//if not yell at the browser for fucking up, and tell it what it did wrong.
|
||||
return module.exports.socketErrorHandler(socket, err.msg, "Caught Exception");
|
||||
//if not yell at the browser for fucking up
|
||||
return module.exports.socketErrorHandler(socket, "Caught Exception", "Caught Exception");
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.socketCriticalExceptionHandler = function(socket, err){
|
||||
//if not yell at the browser for fucking up, and tell it what it did wrong.
|
||||
socket.emit("kick", {type: "Disconnected", reason: `Server Error: ${err.message}`});
|
||||
//If this is a self made problem
|
||||
if(err.custom){
|
||||
//yell at the browser for fucking up, and tell it what it did wrong.
|
||||
socket.emit("kick", {type: "Disconnected", reason: `Server Error: ${err.message}`});
|
||||
}else{
|
||||
//yell at the browser for fucking up
|
||||
socket.emit("kick", {type: "Disconnected", reason: "An unexpected server crash was just prevented. You should probably report this to an admin."});
|
||||
}
|
||||
return socket.disconnect();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue