HTTP404HtmlResponse::operator+(const std::string&)

This commit is contained in:
Veloman Yunkan 2022-03-24 18:57:26 +04:00 committed by Matthieu Gautier
parent d5ae92e4e2
commit 48d377ca44
3 changed files with 10 additions and 3 deletions

View File

@ -877,7 +877,9 @@ std::unique_ptr<Response> InternalServer::handle_raw(const RequestContext& reque
if (archive == nullptr) { if (archive == nullptr) {
const std::string error_details = "No such book: " + bookName; const std::string error_details = "No such book: " + bookName;
return Response::build_404(*this, request.get_full_url(), error_details); return HTTP404HtmlResponse(*this, request)
+ urlNotFoundMsg
+ error_details;
} }
// Remove the beggining of the path: // Remove the beggining of the path:

View File

@ -127,8 +127,12 @@ HTTP404HtmlResponse& HTTP404HtmlResponse::operator+(UrlNotFoundMsg /*unused*/)
{ {
const std::string requestUrl = m_request.get_full_url(); const std::string requestUrl = m_request.get_full_url();
kainjow::mustache::mustache msgTmpl(R"(The requested URL "{{url}}" was not found on this server.)"); kainjow::mustache::mustache msgTmpl(R"(The requested URL "{{url}}" was not found on this server.)");
const auto urlNotFoundMsgText = msgTmpl.render({"url", requestUrl}); return *this + msgTmpl.render({"url", requestUrl});
m_data["details"].push_back({"p", urlNotFoundMsgText}); }
HTTP404HtmlResponse& HTTP404HtmlResponse::operator+(const std::string& msg)
{
m_data["details"].push_back({"p", msg});
return *this; return *this;
} }

View File

@ -185,6 +185,7 @@ struct HTTP404HtmlResponse : ContentResponseBlueprint
const RequestContext& request); const RequestContext& request);
HTTP404HtmlResponse& operator+(UrlNotFoundMsg /*unused*/); HTTP404HtmlResponse& operator+(UrlNotFoundMsg /*unused*/);
HTTP404HtmlResponse& operator+(const std::string& errorDetails);
}; };
class ItemResponse : public Response { class ItemResponse : public Response {