|
@@ -162,7 +162,18 @@ Result<QueryResult> StorageClient::query(const std::string& collection, const Qu
|
|
|
up.limit = static_cast<uint32_t>(opts.page_size);
|
|
up.limit = static_cast<uint32_t>(opts.page_size);
|
|
|
up.offset = static_cast<uint32_t>(std::max(0, (opts.page - 1) * opts.page_size));
|
|
up.offset = static_cast<uint32_t>(std::max(0, (opts.page - 1) * opts.page_size));
|
|
|
|
|
|
|
|
- auto fr = impl_->client_->findWithMetrics(collection, up);
|
|
|
|
|
|
|
+ // smartbotic-database >= 2.4.2 throws on an unknown collection or view
|
|
|
|
|
+ // instead of returning an empty result, so the miss is not mistaken for
|
|
|
|
|
+ // an empty collection. Convert it to our Result contract - callers of
|
|
|
|
|
+ // query() expect an Error, never an exception.
|
|
|
|
|
+ dbc::Client::FindResult fr;
|
|
|
|
|
+ try {
|
|
|
|
|
+ fr = impl_->client_->findWithMetrics(collection, up);
|
|
|
|
|
+ } catch (const std::exception& e) {
|
|
|
|
|
+ return Error(ErrorCode::CollectionNotFound,
|
|
|
|
|
+ "Query failed for '" + collection + "': " + e.what());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
QueryResult out;
|
|
QueryResult out;
|
|
|
out.documents = std::move(fr.documents);
|
|
out.documents = std::move(fr.documents);
|
|
|
out.total_count = static_cast<int64_t>(fr.totalCount);
|
|
out.total_count = static_cast<int64_t>(fr.totalCount);
|