From b4490dcb685c41676dd16fc22c0a5eb058d45e92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Sun, 19 May 2024 14:20:19 +0100 Subject: [PATCH] return early on error case for clarity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Caolán McNamara Change-Id: I0cf892b5772d12b3ca914186c000b18dba912429 --- wsd/ClientRequestDispatcher.cpp | 83 ++++++++++++++++----------------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/wsd/ClientRequestDispatcher.cpp b/wsd/ClientRequestDispatcher.cpp index 77fcf4766..e694c79e7 100644 --- a/wsd/ClientRequestDispatcher.cpp +++ b/wsd/ClientRequestDispatcher.cpp @@ -1720,55 +1720,54 @@ void ClientRequestDispatcher::handleClientProxyRequest(const Poco::Net::HTTPRequ auto docBroker = pair.first; auto errorMsg = pair.second; - if (docBroker) - { - // need to move into the DocumentBroker context before doing session lookup / creation etc. - docBroker->setupTransfer( - disposition, - [docBroker, id = _id, uriPublic, isReadOnly, - requestDetails](const std::shared_ptr& moveSocket) - { - // Now inside the document broker thread ... - LOG_TRC_S("In the docbroker thread for " << docBroker->getDocKey()); - - const int fd = moveSocket->getFD(); - auto streamSocket = std::static_pointer_cast(moveSocket); - try - { - docBroker->handleProxyRequest(id, uriPublic, isReadOnly, requestDetails, - streamSocket); - return; - } - catch (const UnauthorizedRequestException& exc) - { - LOG_ERR_S("Unauthorized Request while starting session on " - << docBroker->getDocKey() << " for socket #" << fd - << ". Terminating connection. Error: " << exc.what()); - } - catch (const StorageConnectionException& exc) - { - LOG_ERR_S("Storage error while starting session on " - << docBroker->getDocKey() << " for socket #" << fd - << ". Terminating connection. Error: " << exc.what()); - } - catch (const std::exception& exc) - { - LOG_ERR_S("Error while starting session on " - << docBroker->getDocKey() << " for socket #" << fd - << ". Terminating connection. Error: " << exc.what()); - } - // badness occurred: - HttpHelper::sendErrorAndShutdown(http::StatusCode::BadRequest, streamSocket); - }); - } - else + if (!docBroker) { LOG_ERR("Failed to find document [" << docKey << "]: " << errorMsg); // badness occurred: auto streamSocket = std::static_pointer_cast(disposition.getSocket()); HttpHelper::sendErrorAndShutdown(http::StatusCode::BadRequest, streamSocket); // FIXME: send docunloading & re-try on client ? + return; } + + // need to move into the DocumentBroker context before doing session lookup / creation etc. + docBroker->setupTransfer( + disposition, + [docBroker, id = _id, uriPublic, isReadOnly, + requestDetails](const std::shared_ptr& moveSocket) + { + // Now inside the document broker thread ... + LOG_TRC_S("In the docbroker thread for " << docBroker->getDocKey()); + + const int fd = moveSocket->getFD(); + auto streamSocket = std::static_pointer_cast(moveSocket); + try + { + docBroker->handleProxyRequest(id, uriPublic, isReadOnly, requestDetails, + streamSocket); + return; + } + catch (const UnauthorizedRequestException& exc) + { + LOG_ERR_S("Unauthorized Request while starting session on " + << docBroker->getDocKey() << " for socket #" << fd + << ". Terminating connection. Error: " << exc.what()); + } + catch (const StorageConnectionException& exc) + { + LOG_ERR_S("Storage error while starting session on " + << docBroker->getDocKey() << " for socket #" << fd + << ". Terminating connection. Error: " << exc.what()); + } + catch (const std::exception& exc) + { + LOG_ERR_S("Error while starting session on " + << docBroker->getDocKey() << " for socket #" << fd + << ". Terminating connection. Error: " << exc.what()); + } + // badness occurred: + HttpHelper::sendErrorAndShutdown(http::StatusCode::BadRequest, streamSocket); + }); } #endif