mirror of
https://github.com/kiwix/libkiwix.git
synced 2026-10-22 09:05:14 -04:00
Correctly handle invalid book.
If user request for a non existent book, we must return a 400 page. (This is done by throwing a `std::invalid_argument` and let the catch handle it)
This commit is contained in:
1 parent
7407f30790
commit
1962262f94
2 files changed
+23
-18
No files matched your search
@@ -558,12 +558,7 @@ std::unique_ptr<Response> 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.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user