noSuchBookErrorMsg()

This commit is contained in:
Veloman Yunkan 2022-03-24 19:10:07 +04:00 committed by Matthieu Gautier
parent 48d377ca44
commit 9bc09a815c
1 changed files with 13 additions and 4 deletions

View File

@ -389,6 +389,16 @@ SuggestionsList_t getSuggestions(SuggestionSearcherCache& cache, const zim::Arch
return suggestions; return suggestions;
} }
namespace
{
std::string noSuchBookErrorMsg(const std::string& bookName)
{
return "No such book: " + bookName;
}
} // unnamed namespace
std::unique_ptr<Response> InternalServer::handle_suggest(const RequestContext& request) std::unique_ptr<Response> InternalServer::handle_suggest(const RequestContext& request)
{ {
if (m_verbose.load()) { if (m_verbose.load()) {
@ -406,7 +416,7 @@ std::unique_ptr<Response> InternalServer::handle_suggest(const RequestContext& r
} }
if (archive == nullptr) { if (archive == nullptr) {
const std::string error_details = "No such book: " + bookName; const std::string error_details = noSuchBookErrorMsg(bookName);
auto response = Response::build_404(*this, "", error_details); auto response = Response::build_404(*this, "", error_details);
return withTaskbarInfo(bookName, nullptr, std::move(response)); return withTaskbarInfo(bookName, nullptr, std::move(response));
} }
@ -617,7 +627,7 @@ std::unique_ptr<Response> InternalServer::handle_random(const RequestContext& re
} }
if (archive == nullptr) { if (archive == nullptr) {
const std::string error_details = "No such book: " + bookName; const std::string error_details = noSuchBookErrorMsg(bookName);
auto response = Response::build_404(*this, "", error_details); auto response = Response::build_404(*this, "", error_details);
return withTaskbarInfo(bookName, nullptr, std::move(response)); return withTaskbarInfo(bookName, nullptr, std::move(response));
} }
@ -876,10 +886,9 @@ std::unique_ptr<Response> InternalServer::handle_raw(const RequestContext& reque
} catch (const std::out_of_range& e) {} } catch (const std::out_of_range& e) {}
if (archive == nullptr) { if (archive == nullptr) {
const std::string error_details = "No such book: " + bookName;
return HTTP404HtmlResponse(*this, request) return HTTP404HtmlResponse(*this, request)
+ urlNotFoundMsg + urlNotFoundMsg
+ error_details; + noSuchBookErrorMsg(bookName);
} }
// Remove the beggining of the path: // Remove the beggining of the path: