From a7651d0e9b9733c55f8161ff697e97620c8de1c2 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 30 May 2022 23:42:22 +0200 Subject: [PATCH] Check early that provided bookIds are valid --- src/server/internalServer.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index 0c302eb79..772f6a4da 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -237,6 +237,14 @@ std::pair 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};