Clear console and properly handle error message when querying database or containers (#1679)

This commit is contained in:
Laurent Nguyen 2023-10-26 15:55:48 +00:00 committed by GitHub
parent 3a703b0bd0
commit 661f6f4bfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 7 deletions

View File

@ -35,6 +35,7 @@ export async function readCollections(databaseId: string): Promise<DataModels.Co
}
}
try {
const responses = await Promise.all(promises);
responses.forEach((response) => {
collections.push(response.resource as DataModels.Collection);
@ -43,6 +44,12 @@ export async function readCollections(databaseId: string): Promise<DataModels.Co
// Sort collections by id before returning
collections.sort((a, b) => a.id.localeCompare(b.id));
return collections;
} catch (error) {
handleError(error, "ReadCollections", `Error while querying containers for database ${databaseId}`);
throw error;
} finally {
clearMessage();
}
}
try {

View File

@ -22,6 +22,13 @@ export async function readDatabases(): Promise<DataModels.Database[]> {
for (const collectionResourceId in tokensData.resourceTokens) {
// Dictionary key looks like this: dbs/SampleDB/colls/Container
const resourceIdObj = collectionResourceId.split("/");
if (resourceIdObj.length !== 4) {
handleError(`Resource key not recognized: ${resourceIdObj}`, "ReadDatabases", `Error while querying databases`);
clearMessage();
return [];
}
const databaseId = resourceIdObj[1];
databaseIdsSet.add(databaseId);
@ -37,6 +44,7 @@ export async function readDatabases(): Promise<DataModels.Database[]> {
id: databaseId,
collections: [],
}));
clearMessage();
return databases;
}