mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-26 12:21:23 +00:00
25 lines
1001 B
TypeScript
25 lines
1001 B
TypeScript
import * as DataModels from "../../Contracts/DataModels";
|
|
import { client } from "../CosmosClient";
|
|
import { logConsoleProgress, logConsoleError } from "../../Utils/NotificationConsoleUtils";
|
|
import { logError } from "../Logger";
|
|
import { sendNotificationForError } from "./sendNotificationForError";
|
|
|
|
export async function readCollection(databaseId: string, collectionId: string): Promise<DataModels.Collection> {
|
|
let collection: DataModels.Collection;
|
|
const clearMessage = logConsoleProgress(`Querying container ${collectionId}`);
|
|
try {
|
|
const response = await client()
|
|
.database(databaseId)
|
|
.container(collectionId)
|
|
.read();
|
|
collection = response.resource as DataModels.Collection;
|
|
} catch (error) {
|
|
logConsoleError(`Error while querying container ${collectionId}:\n ${JSON.stringify(error)}`);
|
|
logError(JSON.stringify(error), "ReadCollection", error.code);
|
|
sendNotificationForError(error);
|
|
throw error;
|
|
}
|
|
clearMessage();
|
|
return collection;
|
|
}
|