mirror of https://github.com/kiwix/libkiwix.git
HTTPErrorResponse no longer accepts std::strings
This commit is contained in:
parent
41f25083da
commit
a7ea908bcd
|
@ -111,6 +111,12 @@ private: // data
|
||||||
const Parameters params;
|
const Parameters params;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline ParameterizedMessage nonParameterizedMessage(const std::string& msgId)
|
||||||
|
{
|
||||||
|
const ParameterizedMessage::Parameters noParams;
|
||||||
|
return ParameterizedMessage(msgId, noParams);
|
||||||
|
}
|
||||||
|
|
||||||
struct LangPreference
|
struct LangPreference
|
||||||
{
|
{
|
||||||
const std::string lang;
|
const std::string lang;
|
||||||
|
|
|
@ -190,12 +190,6 @@ ParameterizedMessage tooManyBooksMsg(size_t nbBooks, size_t limit)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ParameterizedMessage nonParameterizedMessage(const std::string& msgId)
|
|
||||||
{
|
|
||||||
const ParameterizedMessage::Parameters noParams;
|
|
||||||
return ParameterizedMessage(msgId, noParams);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Error : public std::runtime_error {
|
struct Error : public std::runtime_error {
|
||||||
explicit Error(const ParameterizedMessage& message)
|
explicit Error(const ParameterizedMessage& message)
|
||||||
: std::runtime_error("Error while handling request"),
|
: std::runtime_error("Error while handling request"),
|
||||||
|
@ -650,11 +644,11 @@ std::unique_ptr<Response> InternalServer::handle_request(const RequestContext& r
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
fprintf(stderr, "===== Unhandled error : %s\n", e.what());
|
fprintf(stderr, "===== Unhandled error : %s\n", e.what());
|
||||||
return HTTP500Response(*this, request)
|
return HTTP500Response(*this, request)
|
||||||
+ e.what();
|
+ ParameterizedMessage("non-translated-text", {{"MSG", e.what()}});
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
fprintf(stderr, "===== Unhandled unknown error\n");
|
fprintf(stderr, "===== Unhandled unknown error\n");
|
||||||
return HTTP500Response(*this, request)
|
return HTTP500Response(*this, request)
|
||||||
+ "Unknown error";
|
+ nonParameterizedMessage("unknown-error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -205,15 +205,11 @@ UrlNotFoundResponse::UrlNotFoundResponse(const InternalServer& server,
|
||||||
*this += ParameterizedMessage("url-not-found", {{"url", requestUrl}});
|
*this += ParameterizedMessage("url-not-found", {{"url", requestUrl}});
|
||||||
}
|
}
|
||||||
|
|
||||||
HTTPErrorResponse& HTTPErrorResponse::operator+(const std::string& msg)
|
|
||||||
{
|
|
||||||
m_data["details"].push_back({"p", msg});
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
HTTPErrorResponse& HTTPErrorResponse::operator+(const ParameterizedMessage& details)
|
HTTPErrorResponse& HTTPErrorResponse::operator+(const ParameterizedMessage& details)
|
||||||
{
|
{
|
||||||
return *this + details.getText(m_request.get_user_language());
|
const std::string msg = details.getText(m_request.get_user_language());
|
||||||
|
m_data["details"].push_back({"p", msg});
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
HTTPErrorResponse& HTTPErrorResponse::operator+=(const ParameterizedMessage& details)
|
HTTPErrorResponse& HTTPErrorResponse::operator+=(const ParameterizedMessage& details)
|
||||||
|
@ -251,8 +247,7 @@ HTTP500Response::HTTP500Response(const InternalServer& server,
|
||||||
"500-page-title",
|
"500-page-title",
|
||||||
"500-page-heading")
|
"500-page-heading")
|
||||||
{
|
{
|
||||||
// operator+() is a state-modifying operator (akin to operator+=)
|
*this += nonParameterizedMessage("500-page-text");
|
||||||
*this + "An internal server error occured. We are sorry about that :/";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<ContentResponse> HTTP500Response::generateResponseObject() const
|
std::unique_ptr<ContentResponse> HTTP500Response::generateResponseObject() const
|
||||||
|
|
|
@ -169,7 +169,6 @@ struct HTTPErrorResponse : ContentResponseBlueprint
|
||||||
const std::string& headingMsgId,
|
const std::string& headingMsgId,
|
||||||
const std::string& cssUrl = "");
|
const std::string& cssUrl = "");
|
||||||
|
|
||||||
HTTPErrorResponse& operator+(const std::string& msg);
|
|
||||||
HTTPErrorResponse& operator+(const ParameterizedMessage& errorDetails);
|
HTTPErrorResponse& operator+(const ParameterizedMessage& errorDetails);
|
||||||
HTTPErrorResponse& operator+=(const ParameterizedMessage& errorDetails);
|
HTTPErrorResponse& operator+=(const ParameterizedMessage& errorDetails);
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
, "404-page-heading" : "Not Found"
|
, "404-page-heading" : "Not Found"
|
||||||
, "500-page-title" : "Internal Server Error"
|
, "500-page-title" : "Internal Server Error"
|
||||||
, "500-page-heading" : "Internal Server Error"
|
, "500-page-heading" : "Internal Server Error"
|
||||||
|
, "500-page-text": "An internal server error occured. We are sorry about that :/"
|
||||||
, "fulltext-search-unavailable" : "Fulltext search unavailable"
|
, "fulltext-search-unavailable" : "Fulltext search unavailable"
|
||||||
, "no-search-results": "The fulltext search engine is not available for this content."
|
, "no-search-results": "The fulltext search engine is not available for this content."
|
||||||
, "library-button-text": "Go to welcome page"
|
, "library-button-text": "Go to welcome page"
|
||||||
|
@ -52,4 +53,6 @@
|
||||||
, "download-links-heading": "Download links for <b><i>{{BOOK_TITLE}}</i></b>"
|
, "download-links-heading": "Download links for <b><i>{{BOOK_TITLE}}</i></b>"
|
||||||
, "download-links-title": "Download book"
|
, "download-links-title": "Download book"
|
||||||
, "preview-book": "Preview"
|
, "preview-book": "Preview"
|
||||||
|
, "non-translated-text": "{{MSG}}"
|
||||||
|
, "unknown-error": "Unknown error"
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
"404-page-heading": "Heading of the 404 error page",
|
"404-page-heading": "Heading of the 404 error page",
|
||||||
"500-page-title": "Title of the 500 error page",
|
"500-page-title": "Title of the 500 error page",
|
||||||
"500-page-heading": "Heading of the 500 error page",
|
"500-page-heading": "Heading of the 500 error page",
|
||||||
|
"500-page-text": "Text of the 500 error page",
|
||||||
"fulltext-search-unavailable": "Title of the error page returned when search is attempted in a book without fulltext search database",
|
"fulltext-search-unavailable": "Title of the error page returned when search is attempted in a book without fulltext search database",
|
||||||
"no-search-results": "Text of the error page returned when search is attempted in a book without fulltext search database",
|
"no-search-results": "Text of the error page returned when search is attempted in a book without fulltext search database",
|
||||||
"library-button-text": "Tooltip of the button leading to the welcome page",
|
"library-button-text": "Tooltip of the button leading to the welcome page",
|
||||||
|
@ -53,5 +54,7 @@
|
||||||
"welcome-to-kiwix-server": "Title shown in browser's title bar/page tab",
|
"welcome-to-kiwix-server": "Title shown in browser's title bar/page tab",
|
||||||
"download-links-heading": "Heading for no-js download page",
|
"download-links-heading": "Heading for no-js download page",
|
||||||
"download-links-title": "Title for no-js download page",
|
"download-links-title": "Title for no-js download page",
|
||||||
"preview-book": "Tooltip of book-tile leading to the book"
|
"preview-book": "Tooltip of book-tile leading to the book",
|
||||||
|
"non-translated-text": "Used to display text that is generated at runtime and cannot be translated. Nothing to translate about this one.",
|
||||||
|
"unknown-error": "Unknown error"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue