Files
cosmos-explorer/src/Common/dataAccess/readOffers.ts
Craig Boger (from Dev Box) 56f50e1320 Updated to have a write client and multiple read clients. Added enum to help with selection of client based on needed operation.
Need to modify endpoint selection in CosmosClient to select endpoints based on client called.
2024-03-28 15:35:13 -07:00

24 lines
957 B
TypeScript

import { SDKOfferDefinition } from "../../Contracts/DataModels";
import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils";
import { ClientOperationType, client } from "../CosmosClient";
import { getErrorMessage, handleError } from "../ErrorHandlingUtils";
export const readOffers = async (): Promise<SDKOfferDefinition[]> => {
const clearMessage = logConsoleProgress(`Querying offers`);
try {
const response = await client(ClientOperationType.READ).offers.readAll().fetchAll();
return response?.resources;
} catch (error) {
// This should be removed when we can correctly identify if an account is serverless when connected using connection string too.
if (getErrorMessage(error)?.includes("Reading or replacing offers is not supported for serverless accounts")) {
return [];
}
handleError(error, "ReadOffers", `Error while querying offers`);
throw error;
} finally {
clearMessage();
}
};