diff --git a/src/server/response.cpp b/src/server/response.cpp index d4caf8f3..900b96c1 100644 --- a/src/server/response.cpp +++ b/src/server/response.cpp @@ -494,21 +494,27 @@ HTTP400Response::HTTP400Response(const RequestContext& request) HTTP500Response::HTTP500Response(const RequestContext& request, const std::string& root, const std::string& urlPath, - const std::string& /*errorText*/) + const std::string& errorText) : ContentResponseBlueprint(&request, MHD_HTTP_INTERNAL_SERVER_ERROR, "text/html; charset=utf-8", RESOURCE::templates::sexy500_html, /*includeKiwixResponseData=*/true) { - *this->m_data = Data(Data::Object{ - {"root", root }, - {"url_path", urlPath}, - {"PAGE_TITLE", Data::fromMsgId("500-page-title")}, - {"PAGE_HEADING", Data::fromMsgId("500-page-heading")}, - {"PAGE_TEXT", Data::fromMsgId("500-page-text")}, - {"500_img_text", Data::fromMsgId("500-img-text")}, - }); + auto pageParams = Data::Object{ + {"root", root }, + {"url_path", urlPath}, + {"PAGE_TITLE", Data::fromMsgId("500-page-title")}, + {"PAGE_HEADING", Data::fromMsgId("500-page-heading")}, + {"PAGE_TEXT", Data::fromMsgId("500-page-text")}, + {"500_img_text", Data::fromMsgId("500-img-text")}, + }; + + if ( !errorText.empty() ) { + pageParams["error"] = errorText; + } + + *this->m_data = Data(pageParams); } std::unique_ptr Response::build_416(size_t resourceLength) diff --git a/static/templates/sexy500.html b/static/templates/sexy500.html index 2ea67c28..1a2d869c 100644 --- a/static/templates/sexy500.html +++ b/static/templates/sexy500.html @@ -22,5 +22,10 @@

{{PAGE_TEXT}}

{{url_path}}

+{{#error}} +
+

{{error}}

+
+{{/error}} diff --git a/test/server.cpp b/test/server.cpp index a7c63ca4..8aa5d0da 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -1210,7 +1210,8 @@ TEST_F(ServerTest, HttpXmlError) } } -std::string expectedSexy500ErrorHtml(const std::string& url) +std::string expectedSexy500ErrorHtml(const std::string& url, + const std::string& error) { const auto urlWithoutQuery = replace(url, "\\?.*$", ""); const auto htmlSafeUrl = htmlEscape(urlWithoutQuery); @@ -1241,8 +1242,12 @@ std::string expectedSexy500ErrorHtml(const std::string& url) )RAWSTRINGLITERAL" + t[0] + R"RAWSTRINGLITERAL(