From 20b5a2b9716946e8ebf9c6a6ecca23cbcbc7ac2a Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sat, 11 Dec 2021 21:45:12 +0400 Subject: [PATCH] Less confusing 404 errors from /meta endpoint Before this fix the /meta endpoint could return a 404 Not Found page saying The requested URL "/meta" was not found on this server. Error cases producing such a result were: - `/meta?content=NON-EXISTING-BOOK&name=metaname` - `/meta?content=book&name=BAD-META-NAME` Now a proper message is shown for each of those cases. This fix is being done just for consistency (the /meta endpoint is not a user-facing one and the scripts don't bother about error texts). --- src/server/internalServer.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index b2f4ead56..257ef5312 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -386,23 +386,23 @@ std::unique_ptr InternalServer::handle_meta(const RequestContext& requ { std::string bookName; std::string bookId; - std::string meta_name; std::shared_ptr archive; try { bookName = request.get_argument("content"); bookId = mp_nameMapper->getIdForName(bookName); - meta_name = request.get_argument("name"); archive = mp_library->getArchiveById(bookId); } catch (const std::out_of_range& e) { // error handled by the archive == nullptr check below } if (archive == nullptr) { - return Response::build_404(*this, request.get_full_url(), bookName, ""); + const std::string error_details = "No such book: " + bookName; + return Response::build_404(*this, "", bookName, "", error_details); } std::string content; std::string mimeType = "text"; + const auto meta_name = request.get_optional_param("name", std::string()); if (meta_name == "title") { content = getArchiveTitle(*archive); @@ -425,7 +425,8 @@ std::unique_ptr InternalServer::handle_meta(const RequestContext& requ } else if (const unsigned illustrationSize = parseIllustration(meta_name)) { getArchiveFavicon(*archive, illustrationSize, content, mimeType); } else { - return Response::build_404(*this, request.get_full_url(), bookName, ""); + const std::string error_details = "No such metadata item: " + meta_name; + return Response::build_404(*this, "", bookName, "", error_details); } auto response = ContentResponse::build(*this, content, mimeType);