diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index 14aaf3a68..282d622f7 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -558,12 +558,7 @@ std::unique_ptr InternalServer::handle_search(const RequestContext& re bookId = mp_nameMapper->getIdForName(searchInfo.bookName); archive = mp_library->getArchiveById(bookId); } catch (const std::out_of_range&) { - auto data = get_default_data(); - data.set("pattern", encodeDiples(searchInfo.pattern)); - data.set("root", m_root); - auto response = ContentResponse::build(*this, RESOURCE::templates::no_search_result_html, data, "text/html; charset=utf-8"); - response->set_code(MHD_HTTP_NOT_FOUND); - return withTaskbarInfo(searchInfo.bookName, archive.get(), std::move(response)); + throw std::invalid_argument("The requested book doesn't exist."); } } diff --git a/test/server.cpp b/test/server.cpp index 73ad0f83d..97e112b8b 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -290,6 +290,8 @@ TEST_F(ServerTest, UncompressibleContentIsNotCompressed) const char* urls400[] = { "/ROOT/search", "/ROOT/search?content=zimfile", + "/ROOT/search?content=non-existing-book&pattern=asdfqwerty", + "/ROOT/search?content=non-existing-book&pattern=asd )" }, - - { /* url */ "/ROOT/search?content=non-existent-book&pattern=asdfqwerty", - expected_page_title=="Fulltext search unavailable" && - expected_css_url=="/ROOT/skin/search_results.css" && - expected_body==R"( -
Not found
-

- There is no article with the title "asdfqwerty" - and the fulltext search engine is not available for this content. -

-)" }, }; for ( const auto& t : testData ) { @@ -726,6 +716,26 @@ TEST_F(ServerTest, 400WithBodyTesting)

No query provided.

+)" }, + { /* url */ "/ROOT/search?content=non-existing-book&pattern=asdfqwerty", + expected_body==R"( +

Invalid request

+

+ The requested URL "/ROOT/search?content=non-existing-book&pattern=asdfqwerty" is not a valid request. +

+

+ The requested book doesn't exist. +

+)" }, + { /* url */ "/ROOT/search?content=non-existing-book&pattern=a\"