From ae60ba806bfbb7c71840c30b9f1702e316633574 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Thu, 24 Mar 2022 17:22:41 +0400 Subject: [PATCH] Made 404.html error template a little more generic The fact that an info message was moved into C++ code is temporary since it will be moved to a message resource file soon. --- src/server/response.cpp | 10 ++++++---- static/templates/404.html | 11 +++-------- test/server.cpp | 2 -- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/server/response.cpp b/src/server/response.cpp index f4e6f424b..65be83eb4 100644 --- a/src/server/response.cpp +++ b/src/server/response.cpp @@ -86,13 +86,15 @@ std::unique_ptr Response::build_304(const InternalServer& server, cons std::unique_ptr Response::build_404(const InternalServer& server, const std::string& url, const std::string& details) { - MustacheData data; + kainjow::mustache::list pList; if ( !url.empty() ) { - data.set("url", url); + kainjow::mustache::mustache msgTmpl(R"(The requested URL "{{url}}" was not found on this server.)"); + const auto urlNotFoundMsg = msgTmpl.render({"url", url}); + pList.push_back({"p", urlNotFoundMsg}); } - data.set("details", details); + pList.push_back({"p", details}); - return build_404(server, data); + return build_404(server, {"details", pList}); } std::unique_ptr Response::build_404(const InternalServer& server, const kainjow::mustache::data& data) diff --git a/static/templates/404.html b/static/templates/404.html index 2f6cf2acf..795e8c9ef 100644 --- a/static/templates/404.html +++ b/static/templates/404.html @@ -6,15 +6,10 @@

Not Found

- {{#url}} +{{#details}}

- The requested URL "{{url}}" was not found on this server. + {{{p}}}

- {{/url}} - {{#details}} -

- {{{details}}} -

- {{/details}} +{{/details}} diff --git a/test/server.cpp b/test/server.cpp index 658211216..81af4c864 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -530,7 +530,6 @@ TEST_F(ServerTest, 404WithBodyTesting) { /* url */ "/ROOT/random?content=non-existent-book", expected_body==R"(

Not Found

- //EOLWHITESPACEMARKER

No such book: non-existent-book

@@ -539,7 +538,6 @@ TEST_F(ServerTest, 404WithBodyTesting) { /* url */ "/ROOT/suggest?content=no-such-book&term=whatever", expected_body==R"(

Not Found

- //EOLWHITESPACEMARKER

No such book: no-such-book