Check early that provided bookIds are valid

This commit is contained in:
Matthieu Gautier 2022-05-30 23:42:22 +02:00
parent 3bca43344f
commit a7651d0e9b
1 changed files with 8 additions and 0 deletions

View File

@ -237,6 +237,14 @@ std::pair<std::string, Library::BookIdSet> InternalServer::selectBooks(const Req
if (id_vec.empty()) {
throw Error(noValueForArgMsg("books.id"));
}
for(const auto& bookId: id_vec) {
try {
// This is a silly way to check that bookId exists
mp_nameMapper->getNameForId(bookId);
} catch (const std::out_of_range&) {
throw Error(noSuchBookErrorMsg(bookId));
}
}
const auto bookIds = Library::BookIdSet(id_vec.begin(), id_vec.end());
const auto queryString = request.get_query([&](const std::string& key){return key == "books.id";}, true);
return {queryString, bookIds};