From 646662319e02596fd59cea7056f5a04f6d874bf0 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Fri, 24 Apr 2020 18:41:25 +0200 Subject: [PATCH] Added error checking for message response handling and executor for executing the commands --- source/connection/connection.d | 22 ++++++++++++++++------ source/handlers/response.d | 6 ++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/source/connection/connection.d b/source/connection/connection.d index d32a31e..2a70e43 100644 --- a/source/connection/connection.d +++ b/source/connection/connection.d @@ -585,14 +585,24 @@ public class BesterConnection : Thread /* TODO: Implement me */ debugPrint("Chosen handler for payload type \"" ~ payloadType ~ "\" is " ~ chosenHandler.getPluginName()); - /* TODO: Collect return value */ - HandlerResponse handlerResponse = new HandlerResponse(handlerRun(chosenHandler, payloadData)); + try + { + /* TODO: Collect return value */ + HandlerResponse handlerResponse = new HandlerResponse(handlerRun(chosenHandler, payloadData)); + /* TODO: Continue here, we will make all error handling do on construction as to make this all more compact */ + debugPrint("<<< Message Handler [" ~ chosenHandler.getPluginName() ~ "] response >>>\n\n" ~ handlerResponse.toString()); - /* TODO: Continue here, we will make all error handling do on construction as to make this all more compact */ - - - debugPrint("<<< Message Handler [" ~ chosenHandler.getPluginName() ~ "] response >>>\n\n" ~ handlerResponse.toString()); + /* Execute the message handler's command */ + handlerResponse.execute(this); + } + catch(ResponseError e) + { + /* In the case of an error with the message handler, send an error to the client/server */ + + /* TODO: Send error here */ + } + /* TODO: Handle response */ } diff --git a/source/handlers/response.d b/source/handlers/response.d index ead2aad..dc23fbd 100644 --- a/source/handlers/response.d +++ b/source/handlers/response.d @@ -5,6 +5,7 @@ import std.conv : to; import utils.debugging : debugPrint; import std.string : cmp; import std.stdio : writeln; +import connection.connection; public class HandlerResponse { @@ -112,6 +113,11 @@ public class HandlerResponse } + public void execute(BesterConnection originalRequester) + { + /* TODO: Implement me */ + } + override public string toString() { return messageResponse.toPrettyString();