diff --git a/src/Common/CosmosClient.ts b/src/Common/CosmosClient.ts index 8da830781..de71c11b1 100644 --- a/src/Common/CosmosClient.ts +++ b/src/Common/CosmosClient.ts @@ -69,7 +69,7 @@ export async function getTokenFromAuthService(verb: string, resourceType: string const result = JSON.parse(await response.json()); return result; } catch (error) { - logConsoleError(`Failed to get authorization headers for ${resourceType}: ${JSON.stringify(error)}`); + logConsoleError(`Failed to get authorization headers for ${resourceType}: ${error.message}`); return Promise.reject(error); } } diff --git a/src/Common/DocumentClientUtilityBase.ts b/src/Common/DocumentClientUtilityBase.ts index fc021b070..d8bd683c1 100644 --- a/src/Common/DocumentClientUtilityBase.ts +++ b/src/Common/DocumentClientUtilityBase.ts @@ -1,17 +1,14 @@ import { ConflictDefinition, ItemDefinition, QueryIterator, Resource } from "@azure/cosmos"; -import { RequestOptions } from "@azure/cosmos/dist-esm"; import Q from "q"; -import * as DataModels from "../Contracts/DataModels"; import * as ViewModels from "../Contracts/ViewModels"; import ConflictId from "../Explorer/Tree/ConflictId"; import DocumentId from "../Explorer/Tree/DocumentId"; import StoredProcedure from "../Explorer/Tree/StoredProcedure"; -import { logConsoleError, logConsoleInfo, logConsoleProgress } from "../Utils/NotificationConsoleUtils"; +import { logConsoleInfo, logConsoleProgress } from "../Utils/NotificationConsoleUtils"; import * as Constants from "./Constants"; -import { sendNotificationForError } from "./dataAccess/sendNotificationForError"; import * as DataAccessUtilityBase from "./DataAccessUtilityBase"; import { MinimalQueryIterator, nextPage } from "./IteratorUtilities"; -import * as Logger from "./Logger"; +import { handleError } from "./ErrorHandlingUtils"; // TODO: Log all promise resolutions and errors with verbosity levels export function queryDocuments( @@ -59,13 +56,11 @@ export function executeStoredProcedure( ); }, (error: any) => { - logConsoleError( - `Failed to execute stored procedure ${storedProcedure.id()} for container ${storedProcedure.collection.id()}: ${JSON.stringify( - error - )}` + handleError( + error, + `Failed to execute stored procedure ${storedProcedure.id()} for container ${storedProcedure.collection.id()}`, + "ExecuteStoredProcedure" ); - Logger.logError(JSON.stringify(error), "ExecuteStoredProcedure", error.code); - sendNotificationForError(error); deferred.reject(error); } ) @@ -93,9 +88,7 @@ export function queryDocumentsPage( deferred.resolve(result); }, (error: any) => { - logConsoleError(`Failed to query ${entityName} for container ${resourceName}: ${JSON.stringify(error)}`); - Logger.logError(JSON.stringify(error), "QueryDocumentsPage", error.code); - sendNotificationForError(error); + handleError(error, `Failed to query ${entityName} for container ${resourceName}`, "QueryDocumentsPage"); deferred.reject(error); } ) @@ -116,9 +109,7 @@ export function readDocument(collection: ViewModels.CollectionBase, documentId: deferred.resolve(document); }, (error: any) => { - logConsoleError(`Failed to read ${entityName} ${documentId.id()}: ${JSON.stringify(error)}`); - Logger.logError(JSON.stringify(error), "ReadDocument", error.code); - sendNotificationForError(error); + handleError(error, `Failed to read ${entityName} ${documentId.id()}`, "ReadDocument"); deferred.reject(error); } ) @@ -144,9 +135,7 @@ export function updateDocument( deferred.resolve(updatedDocument); }, (error: any) => { - logConsoleError(`Failed to update ${entityName} ${documentId.id()}: ${JSON.stringify(error)}`); - Logger.logError(JSON.stringify(error), "UpdateDocument", error.code); - sendNotificationForError(error); + handleError(error, `Failed to update ${entityName} ${documentId.id()}`, "UpdateDocument"); deferred.reject(error); } ) @@ -168,11 +157,7 @@ export function createDocument(collection: ViewModels.CollectionBase, newDocumen deferred.resolve(savedDocument); }, (error: any) => { - logConsoleError( - `Error while creating new ${entityName} for container ${collection.id()}:\n ${JSON.stringify(error)}` - ); - Logger.logError(JSON.stringify(error), "CreateDocument", error.code); - sendNotificationForError(error); + handleError(error, `Error while creating new ${entityName} for container ${collection.id()}`, "CreateDocument"); deferred.reject(error); } ) @@ -194,9 +179,7 @@ export function deleteDocument(collection: ViewModels.CollectionBase, documentId deferred.resolve(response); }, (error: any) => { - logConsoleError(`Error while deleting ${entityName} ${documentId.id()}:\n ${JSON.stringify(error)}`); - Logger.logError(JSON.stringify(error), "DeleteDocument", error.code); - sendNotificationForError(error); + handleError(error, `Error while deleting ${entityName} ${documentId.id()}`, "DeleteDocument"); deferred.reject(error); } ) @@ -222,9 +205,7 @@ export function deleteConflict( deferred.resolve(response); }, (error: any) => { - logConsoleError(`Error while deleting conflict ${conflictId.id()}:\n ${JSON.stringify(error)}`); - Logger.logError(JSON.stringify(error), "DeleteConflict", error.code); - sendNotificationForError(error); + handleError(error, `Error while deleting conflict ${conflictId.id()}`, "DeleteConflict"); deferred.reject(error); } ) diff --git a/src/Common/ErrorHandlingUtils.ts b/src/Common/ErrorHandlingUtils.ts new file mode 100644 index 000000000..f100e0b07 --- /dev/null +++ b/src/Common/ErrorHandlingUtils.ts @@ -0,0 +1,11 @@ +import { CosmosError, sendNotificationForError } from "./dataAccess/sendNotificationForError"; +import { logConsoleError } from "../Utils/NotificationConsoleUtils"; +import { logError } from "./Logger"; +import { replaceKnownError } from "./ErrorParserUtility"; + +export const handleError = (error: CosmosError, consoleErrorPrefix: string, area: string): void => { + const sanitizedErrorMsg = replaceKnownError(error.message); + logConsoleError(`${consoleErrorPrefix}:\n ${sanitizedErrorMsg}`); + logError(sanitizedErrorMsg, area, error.code); + sendNotificationForError(error); +}; diff --git a/src/Common/QueriesClient.ts b/src/Common/QueriesClient.ts index e15fff5ce..c54d167fc 100644 --- a/src/Common/QueriesClient.ts +++ b/src/Common/QueriesClient.ts @@ -53,7 +53,7 @@ export class QueriesClient { return Promise.resolve(collection); }, (error: any) => { - const stringifiedError: string = JSON.stringify(error); + const stringifiedError: string = error.message; NotificationConsoleUtils.logConsoleMessage( ConsoleDataType.Error, `Failed to set up account for saving queries: ${stringifiedError}` @@ -163,7 +163,7 @@ export class QueriesClient { return Promise.resolve(queries); }, (error: any) => { - const stringifiedError: string = JSON.stringify(error); + const stringifiedError: string = error.message; NotificationConsoleUtils.logConsoleMessage( ConsoleDataType.Error, `Failed to fetch saved queries: ${stringifiedError}` @@ -175,7 +175,7 @@ export class QueriesClient { }, (error: any) => { // should never get into this state but we handle this regardless - const stringifiedError: string = JSON.stringify(error); + const stringifiedError: string = error.message; NotificationConsoleUtils.logConsoleMessage( ConsoleDataType.Error, `Failed to fetch saved queries: ${stringifiedError}` @@ -232,7 +232,7 @@ export class QueriesClient { return Promise.resolve(); }, (error: any) => { - const stringifiedError: string = JSON.stringify(error); + const stringifiedError: string = error.message; NotificationConsoleUtils.logConsoleMessage( ConsoleDataType.Error, `Failed to delete query ${query.queryName}: ${stringifiedError}` diff --git a/src/Common/dataAccess/createCollection.ts b/src/Common/dataAccess/createCollection.ts index 413481c90..3632ab8df 100644 --- a/src/Common/dataAccess/createCollection.ts +++ b/src/Common/dataAccess/createCollection.ts @@ -1,5 +1,4 @@ import * as DataModels from "../../Contracts/DataModels"; -import * as ErrorParserUtility from "../ErrorParserUtility"; import { AuthType } from "../../AuthType"; import { ContainerResponse, DatabaseResponse } from "@azure/cosmos"; import { ContainerRequest } from "@azure/cosmos/dist-esm/client/Container/ContainerRequest"; @@ -23,21 +22,20 @@ import { getGremlinGraph } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; import { createUpdateTable, getTable } from "../../Utils/arm/generatedClients/2020-04-01/tableResources"; -import { logConsoleProgress, logConsoleError, logConsoleInfo } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; +import { logConsoleProgress, logConsoleInfo } from "../../Utils/NotificationConsoleUtils"; import { refreshCachedResources } from "../DataAccessUtilityBase"; -import { sendNotificationForError } from "./sendNotificationForError"; import { userContext } from "../../UserContext"; import { createDatabase } from "./createDatabase"; import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants"; +import { handleError } from "../ErrorHandlingUtils"; export const createCollection = async (params: DataModels.CreateCollectionParams): Promise => { - let collection: DataModels.Collection; const clearMessage = logConsoleProgress( `Creating a new container ${params.collectionId} for database ${params.databaseId}` ); try { + let collection: DataModels.Collection; if (window.authType === AuthType.AAD && !userContext.useSDKOperations) { if (params.createNewDatabase) { const createDatabaseParams: DataModels.CreateDatabaseParams = { @@ -54,18 +52,16 @@ export const createCollection = async (params: DataModels.CreateCollectionParams } else { collection = await createCollectionWithSDK(params); } + + logConsoleInfo(`Successfully created container ${params.collectionId}`); + await refreshCachedResources(); + return collection; } catch (error) { - const sanitizedError = ErrorParserUtility.replaceKnownError(JSON.stringify(error)); - logConsoleError(`Error while creating container ${params.collectionId}:\n ${sanitizedError}`); - logError(JSON.stringify(error), "CreateCollection", error.code); - sendNotificationForError(error); - clearMessage(); + handleError(error, `Error while creating container ${params.collectionId}`, "CreateCollection"); throw error; + } finally { + clearMessage(); } - logConsoleInfo(`Successfully created container ${params.collectionId}`); - await refreshCachedResources(); - clearMessage(); - return collection; }; const createCollectionWithARM = async (params: DataModels.CreateCollectionParams): Promise => { diff --git a/src/Common/dataAccess/createDatabase.ts b/src/Common/dataAccess/createDatabase.ts index eab7fe646..709e6ce90 100644 --- a/src/Common/dataAccess/createDatabase.ts +++ b/src/Common/dataAccess/createDatabase.ts @@ -24,36 +24,31 @@ import { createUpdateGremlinDatabase, getGremlinDatabase } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; -import { logConsoleProgress, logConsoleError, logConsoleInfo } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; +import { handleError } from "../ErrorHandlingUtils"; +import { logConsoleProgress, logConsoleInfo } from "../../Utils/NotificationConsoleUtils"; import { refreshCachedOffers, refreshCachedResources } from "../DataAccessUtilityBase"; -import { sendNotificationForError } from "./sendNotificationForError"; import { userContext } from "../../UserContext"; export async function createDatabase(params: DataModels.CreateDatabaseParams): Promise { - let database: DataModels.Database; const clearMessage = logConsoleProgress(`Creating a new database ${params.databaseId}`); try { if (userContext.defaultExperience === DefaultAccountExperienceType.Table) { throw new Error("Creating database resources is not allowed for tables accounts"); } - if (window.authType === AuthType.AAD && !userContext.useSDKOperations) { - database = await createDatabaseWithARM(params); - } else { - database = await createDatabaseWithSDK(params); - } + const database: DataModels.Database = await (window.authType === AuthType.AAD && !userContext.useSDKOperations + ? createDatabaseWithARM(params) + : createDatabaseWithSDK(params)); + + await refreshCachedResources(); + await refreshCachedOffers(); + logConsoleInfo(`Successfully created database ${params.databaseId}`); + return database; } catch (error) { - logConsoleError(`Error while creating database ${params.databaseId}:\n ${error.message}`); - logError(JSON.stringify(error), "CreateDatabase", error.code); - sendNotificationForError(error); - clearMessage(); + handleError(error, `Error while creating database ${params.databaseId}`, "CreateDatabase"); throw error; + } finally { + clearMessage(); } - logConsoleInfo(`Successfully created database ${params.databaseId}`); - await refreshCachedResources(); - await refreshCachedOffers(); - clearMessage(); - return database; } async function createDatabaseWithARM(params: DataModels.CreateDatabaseParams): Promise { diff --git a/src/Common/dataAccess/createStoredProcedure.ts b/src/Common/dataAccess/createStoredProcedure.ts index 14a21b473..5c7b2f748 100644 --- a/src/Common/dataAccess/createStoredProcedure.ts +++ b/src/Common/dataAccess/createStoredProcedure.ts @@ -9,9 +9,8 @@ import { createUpdateSqlStoredProcedure, getSqlStoredProcedure } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { logConsoleError, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; -import { sendNotificationForError } from "./sendNotificationForError"; +import { handleError } from "../ErrorHandlingUtils"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { userContext } from "../../UserContext"; export async function createStoredProcedure( @@ -66,9 +65,7 @@ export async function createStoredProcedure( .scripts.storedProcedures.create(storedProcedure); return response?.resource; } catch (error) { - logConsoleError(`Error while creating stored procedure ${storedProcedure.id}:\n ${JSON.stringify(error)}`); - logError(JSON.stringify(error), "CreateStoredProcedure", error.code); - sendNotificationForError(error); + handleError(error, `Error while creating stored procedure ${storedProcedure.id}`, "CreateStoredProcedure"); throw error; } finally { clearMessage(); diff --git a/src/Common/dataAccess/createTrigger.ts b/src/Common/dataAccess/createTrigger.ts index 39747ed0e..daf970582 100644 --- a/src/Common/dataAccess/createTrigger.ts +++ b/src/Common/dataAccess/createTrigger.ts @@ -29,7 +29,7 @@ export async function createTrigger( trigger.id ); if (getResponse?.properties?.resource) { - throw new Error(`Create trigger failed: trigger with id ${trigger.id} already exists`); + throw new Error(`Create trigger failed: ${trigger.id} already exists`); } } catch (error) { if (error.code !== "NotFound") { @@ -61,8 +61,8 @@ export async function createTrigger( .scripts.triggers.create(trigger); return response.resource; } catch (error) { - logConsoleError(`Error while creating trigger ${trigger.id}:\n ${JSON.stringify(error)}`); - logError(JSON.stringify(error), "CreateTrigger", error.code); + logConsoleError(`Error while creating trigger ${trigger.id}:\n ${error.message}`); + logError(error.message, "CreateTrigger", error.code); sendNotificationForError(error); throw error; } finally { diff --git a/src/Common/dataAccess/createUserDefinedFunction.ts b/src/Common/dataAccess/createUserDefinedFunction.ts index 0463cf1c7..350270177 100644 --- a/src/Common/dataAccess/createUserDefinedFunction.ts +++ b/src/Common/dataAccess/createUserDefinedFunction.ts @@ -9,9 +9,8 @@ import { createUpdateSqlUserDefinedFunction, getSqlUserDefinedFunction } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { logConsoleError, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; -import { sendNotificationForError } from "./sendNotificationForError"; +import { handleError } from "../ErrorHandlingUtils"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { userContext } from "../../UserContext"; export async function createUserDefinedFunction( @@ -66,9 +65,11 @@ export async function createUserDefinedFunction( .scripts.userDefinedFunctions.create(userDefinedFunction); return response?.resource; } catch (error) { - logConsoleError(`Error while creating user defined function ${userDefinedFunction.id}:\n ${JSON.stringify(error)}`); - logError(JSON.stringify(error), "CreateUserupdateUserDefinedFunction", error.code); - sendNotificationForError(error); + handleError( + error, + `Error while creating user defined function ${userDefinedFunction.id}`, + "CreateUserupdateUserDefinedFunction" + ); throw error; } finally { clearMessage(); diff --git a/src/Common/dataAccess/deleteCollection.ts b/src/Common/dataAccess/deleteCollection.ts index 75d282fce..26f62e200 100644 --- a/src/Common/dataAccess/deleteCollection.ts +++ b/src/Common/dataAccess/deleteCollection.ts @@ -5,9 +5,8 @@ import { deleteCassandraTable } from "../../Utils/arm/generatedClients/2020-04-0 import { deleteMongoDBCollection } from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; import { deleteGremlinGraph } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; import { deleteTable } from "../../Utils/arm/generatedClients/2020-04-01/tableResources"; -import { logConsoleError, logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; -import { sendNotificationForError } from "./sendNotificationForError"; +import { handleError } from "../ErrorHandlingUtils"; +import { logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { userContext } from "../../UserContext"; import { client } from "../CosmosClient"; import { refreshCachedResources } from "../DataAccessUtilityBase"; @@ -23,15 +22,14 @@ export async function deleteCollection(databaseId: string, collectionId: string) .container(collectionId) .delete(); } + logConsoleInfo(`Successfully deleted container ${collectionId}`); + await refreshCachedResources(); } catch (error) { - logConsoleError(`Error while deleting container ${collectionId}:\n ${JSON.stringify(error)}`); - logError(JSON.stringify(error), "DeleteCollection", error.code); - sendNotificationForError(error); + handleError(error, `Error while deleting container ${collectionId}`, "DeleteCollection"); throw error; + } finally { + clearMessage(); } - logConsoleInfo(`Successfully deleted container ${collectionId}`); - clearMessage(); - await refreshCachedResources(); } function deleteCollectionWithARM(databaseId: string, collectionId: string): Promise { diff --git a/src/Common/dataAccess/deleteDatabase.ts b/src/Common/dataAccess/deleteDatabase.ts index 40bfca402..d7fbfd28e 100644 --- a/src/Common/dataAccess/deleteDatabase.ts +++ b/src/Common/dataAccess/deleteDatabase.ts @@ -4,12 +4,11 @@ import { deleteSqlDatabase } from "../../Utils/arm/generatedClients/2020-04-01/s import { deleteCassandraKeyspace } from "../../Utils/arm/generatedClients/2020-04-01/cassandraResources"; import { deleteMongoDBDatabase } from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; import { deleteGremlinDatabase } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; -import { logConsoleError, logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; +import { handleError } from "../ErrorHandlingUtils"; +import { logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { userContext } from "../../UserContext"; import { client } from "../CosmosClient"; import { refreshCachedResources } from "../DataAccessUtilityBase"; -import { logError } from "../Logger"; -import { sendNotificationForError } from "./sendNotificationForError"; export async function deleteDatabase(databaseId: string): Promise { const clearMessage = logConsoleProgress(`Deleting database ${databaseId}`); @@ -25,15 +24,14 @@ export async function deleteDatabase(databaseId: string): Promise { .database(databaseId) .delete(); } + logConsoleInfo(`Successfully deleted database ${databaseId}`); + await refreshCachedResources(); } catch (error) { - logConsoleError(`Error while deleting database ${databaseId}:\n ${JSON.stringify(error)}`); - logError(JSON.stringify(error), "DeleteDatabase", error.code); - sendNotificationForError(error); + handleError(error, `Error while deleting database ${databaseId}`, "DeleteDatabase"); throw error; + } finally { + clearMessage(); } - logConsoleInfo(`Successfully deleted database ${databaseId}`); - clearMessage(); - await refreshCachedResources(); } function deleteDatabaseWithARM(databaseId: string): Promise { diff --git a/src/Common/dataAccess/deleteStoredProcedure.ts b/src/Common/dataAccess/deleteStoredProcedure.ts index d30cf9b48..2da1a409f 100644 --- a/src/Common/dataAccess/deleteStoredProcedure.ts +++ b/src/Common/dataAccess/deleteStoredProcedure.ts @@ -1,9 +1,8 @@ import { AuthType } from "../../AuthType"; import { client } from "../CosmosClient"; import { deleteSqlStoredProcedure } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { logConsoleError, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; -import { sendNotificationForError } from "./sendNotificationForError"; +import { handleError } from "../ErrorHandlingUtils"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { userContext } from "../../UserContext"; export async function deleteStoredProcedure( @@ -30,9 +29,7 @@ export async function deleteStoredProcedure( .delete(); } } catch (error) { - logConsoleError(`Error while deleting stored procedure ${storedProcedureId}:\n ${JSON.stringify(error)}`); - logError(JSON.stringify(error), "DeleteStoredProcedure", error.code); - sendNotificationForError(error); + handleError(error, `Error while deleting stored procedure ${storedProcedureId}`, "DeleteStoredProcedure"); throw error; } finally { clearMessage(); diff --git a/src/Common/dataAccess/deleteTrigger.ts b/src/Common/dataAccess/deleteTrigger.ts index 613ab82ac..e4d6d7840 100644 --- a/src/Common/dataAccess/deleteTrigger.ts +++ b/src/Common/dataAccess/deleteTrigger.ts @@ -1,9 +1,8 @@ import { AuthType } from "../../AuthType"; import { client } from "../CosmosClient"; import { deleteSqlTrigger } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { logConsoleError, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; -import { sendNotificationForError } from "./sendNotificationForError"; +import { handleError } from "../ErrorHandlingUtils"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { userContext } from "../../UserContext"; export async function deleteTrigger(databaseId: string, collectionId: string, triggerId: string): Promise { @@ -26,9 +25,7 @@ export async function deleteTrigger(databaseId: string, collectionId: string, tr .delete(); } } catch (error) { - logConsoleError(`Error while deleting trigger ${triggerId}:\n ${JSON.stringify(error)}`); - logError(JSON.stringify(error), "DeleteTrigger", error.code); - sendNotificationForError(error); + handleError(error, `Error while deleting trigger ${triggerId}`, "DeleteTrigger"); throw error; } finally { clearMessage(); diff --git a/src/Common/dataAccess/deleteUserDefinedFunction.ts b/src/Common/dataAccess/deleteUserDefinedFunction.ts index 04dfd81cd..5d195baa9 100644 --- a/src/Common/dataAccess/deleteUserDefinedFunction.ts +++ b/src/Common/dataAccess/deleteUserDefinedFunction.ts @@ -1,9 +1,8 @@ import { AuthType } from "../../AuthType"; import { client } from "../CosmosClient"; import { deleteSqlUserDefinedFunction } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { logConsoleError, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; -import { sendNotificationForError } from "./sendNotificationForError"; +import { handleError } from "../ErrorHandlingUtils"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { userContext } from "../../UserContext"; export async function deleteUserDefinedFunction(databaseId: string, collectionId: string, id: string): Promise { @@ -26,9 +25,7 @@ export async function deleteUserDefinedFunction(databaseId: string, collectionId .delete(); } } catch (error) { - logConsoleError(`Error while deleting user defined function ${id}:\n ${JSON.stringify(error)}`); - logError(JSON.stringify(error), "DeleteUserDefinedFunction", error.code); - sendNotificationForError(error); + handleError(error, `Error while deleting user defined function ${id}`, "DeleteUserDefinedFunction"); throw error; } finally { clearMessage(); diff --git a/src/Common/dataAccess/readCollection.ts b/src/Common/dataAccess/readCollection.ts index a947af6b2..0b434ba03 100644 --- a/src/Common/dataAccess/readCollection.ts +++ b/src/Common/dataAccess/readCollection.ts @@ -1,8 +1,7 @@ import * as DataModels from "../../Contracts/DataModels"; import { client } from "../CosmosClient"; -import { logConsoleProgress, logConsoleError } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; -import { sendNotificationForError } from "./sendNotificationForError"; +import { handleError } from "../ErrorHandlingUtils"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; export async function readCollection(databaseId: string, collectionId: string): Promise { let collection: DataModels.Collection; @@ -14,9 +13,7 @@ export async function readCollection(databaseId: string, collectionId: string): .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); + handleError(error, `Error while querying container ${collectionId}`, "ReadCollection"); throw error; } clearMessage(); diff --git a/src/Common/dataAccess/readCollectionOffer.ts b/src/Common/dataAccess/readCollectionOffer.ts index 29501a9f2..ad4c8eef5 100644 --- a/src/Common/dataAccess/readCollectionOffer.ts +++ b/src/Common/dataAccess/readCollectionOffer.ts @@ -4,15 +4,14 @@ import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType import { HttpHeaders } from "../Constants"; import { RequestOptions } from "@azure/cosmos/dist-esm"; import { client } from "../CosmosClient"; +import { handleError } from "../ErrorHandlingUtils"; import { getSqlContainerThroughput } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; import { getMongoDBCollectionThroughput } from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; import { getCassandraTableThroughput } from "../../Utils/arm/generatedClients/2020-04-01/cassandraResources"; import { getGremlinGraphThroughput } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; import { getTableThroughput } from "../../Utils/arm/generatedClients/2020-04-01/tableResources"; -import { logConsoleProgress, logConsoleError } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { readOffers } from "./readOffers"; -import { sendNotificationForError } from "./sendNotificationForError"; import { userContext } from "../../UserContext"; export const readCollectionOffer = async ( @@ -57,9 +56,7 @@ export const readCollectionOffer = async ( } ); } catch (error) { - logConsoleError(`Error while querying offer for collection ${params.collectionId}:\n ${JSON.stringify(error)}`); - logError(JSON.stringify(error), "ReadCollectionOffer", error.code); - sendNotificationForError(error); + handleError(error, `Error while querying offer for collection ${params.collectionId}`, "ReadCollectionOffer"); throw error; } finally { clearMessage(); diff --git a/src/Common/dataAccess/readCollectionQuotaInfo.ts b/src/Common/dataAccess/readCollectionQuotaInfo.ts index b2cdbc273..574913f06 100644 --- a/src/Common/dataAccess/readCollectionQuotaInfo.ts +++ b/src/Common/dataAccess/readCollectionQuotaInfo.ts @@ -5,9 +5,8 @@ import { ContainerDefinition, Resource } from "@azure/cosmos"; import { HttpHeaders } from "../Constants"; import { RequestOptions } from "@azure/cosmos/dist-esm"; import { client } from "../CosmosClient"; -import { logConsoleProgress, logConsoleError } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; -import { sendNotificationForError } from "./sendNotificationForError"; +import { handleError } from "../ErrorHandlingUtils"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; interface ResourceWithStatistics { statistics: DataModels.Statistic[]; @@ -38,9 +37,7 @@ export const readCollectionQuotaInfo = async ( return quota; } catch (error) { - logConsoleError(`Error while querying quota info for container ${collection.id}:\n ${JSON.stringify(error)}`); - logError(JSON.stringify(error), "ReadCollectionQuotaInfo", error.code); - sendNotificationForError(error); + handleError(error, `Error while querying quota info for container ${collection.id}`, "ReadCollectionQuotaInfo"); throw error; } finally { clearMessage(); diff --git a/src/Common/dataAccess/readCollections.ts b/src/Common/dataAccess/readCollections.ts index 6ebca7b13..405232f49 100644 --- a/src/Common/dataAccess/readCollections.ts +++ b/src/Common/dataAccess/readCollections.ts @@ -2,18 +2,16 @@ import * as DataModels from "../../Contracts/DataModels"; import { AuthType } from "../../AuthType"; import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { client } from "../CosmosClient"; +import { handleError } from "../ErrorHandlingUtils"; import { listSqlContainers } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; import { listCassandraTables } from "../../Utils/arm/generatedClients/2020-04-01/cassandraResources"; import { listMongoDBCollections } from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; import { listGremlinGraphs } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; import { listTables } from "../../Utils/arm/generatedClients/2020-04-01/tableResources"; -import { logConsoleProgress, logConsoleError } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; -import { sendNotificationForError } from "./sendNotificationForError"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { userContext } from "../../UserContext"; export async function readCollections(databaseId: string): Promise { - let collections: DataModels.Collection[]; const clearMessage = logConsoleProgress(`Querying containers for database ${databaseId}`); try { if ( @@ -22,22 +20,20 @@ export async function readCollections(databaseId: string): Promise { diff --git a/src/Common/dataAccess/readDatabaseOffer.ts b/src/Common/dataAccess/readDatabaseOffer.ts index 2a6f67694..4ad34e578 100644 --- a/src/Common/dataAccess/readDatabaseOffer.ts +++ b/src/Common/dataAccess/readDatabaseOffer.ts @@ -8,10 +8,9 @@ import { getSqlDatabaseThroughput } from "../../Utils/arm/generatedClients/2020- import { getMongoDBDatabaseThroughput } from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; import { getCassandraKeyspaceThroughput } from "../../Utils/arm/generatedClients/2020-04-01/cassandraResources"; import { getGremlinDatabaseThroughput } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; -import { logConsoleProgress, logConsoleError } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; +import { handleError } from "../ErrorHandlingUtils"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { readOffers } from "./readOffers"; -import { sendNotificationForError } from "./sendNotificationForError"; import { userContext } from "../../UserContext"; export const readDatabaseOffer = async ( @@ -48,9 +47,7 @@ export const readDatabaseOffer = async ( } ); } catch (error) { - logConsoleError(`Error while querying offer for database ${params.databaseId}:\n ${JSON.stringify(error)}`); - logError(JSON.stringify(error), "ReadDatabaseOffer", error.code); - sendNotificationForError(error); + handleError(error, `Error while querying offer for database ${params.databaseId}`, "ReadDatabaseOffer"); throw error; } finally { clearMessage(); diff --git a/src/Common/dataAccess/readDatabases.ts b/src/Common/dataAccess/readDatabases.ts index 5f65f526b..1f5d35d33 100644 --- a/src/Common/dataAccess/readDatabases.ts +++ b/src/Common/dataAccess/readDatabases.ts @@ -2,13 +2,12 @@ import * as DataModels from "../../Contracts/DataModels"; import { AuthType } from "../../AuthType"; import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { client } from "../CosmosClient"; +import { handleError } from "../ErrorHandlingUtils"; import { listSqlDatabases } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; import { listCassandraKeyspaces } from "../../Utils/arm/generatedClients/2020-04-01/cassandraResources"; import { listMongoDBDatabases } from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; import { listGremlinDatabases } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; -import { logConsoleProgress, logConsoleError } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; -import { sendNotificationForError } from "./sendNotificationForError"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { userContext } from "../../UserContext"; export async function readDatabases(): Promise { @@ -28,9 +27,7 @@ export async function readDatabases(): Promise { databases = sdkResponse.resources as DataModels.Database[]; } } catch (error) { - logConsoleError(`Error while querying databases:\n ${JSON.stringify(error)}`); - logError(JSON.stringify(error), "ReadDatabases", error.code); - sendNotificationForError(error); + handleError(error, `Error while querying databases`, "ReadDatabases"); throw error; } clearMessage(); diff --git a/src/Common/dataAccess/readOffers.ts b/src/Common/dataAccess/readOffers.ts index 303f18689..6220bc17c 100644 --- a/src/Common/dataAccess/readOffers.ts +++ b/src/Common/dataAccess/readOffers.ts @@ -3,10 +3,9 @@ import { ClientDefaults } from "../Constants"; import { MessageTypes } from "../../Contracts/ExplorerContracts"; import { Platform, configContext } from "../../ConfigContext"; import { client } from "../CosmosClient"; -import { logConsoleProgress, logConsoleError } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; +import { handleError } from "../ErrorHandlingUtils"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { sendCachedDataMessage } from "../MessageHandler"; -import { sendNotificationForError } from "./sendNotificationForError"; import { userContext } from "../../UserContext"; export const readOffers = async (): Promise => { @@ -36,9 +35,7 @@ export const readOffers = async (): Promise => { return []; } - logConsoleError(`Error while querying offers:\n ${JSON.stringify(error)}`); - logError(JSON.stringify(error), "ReadOffers", error.code); - sendNotificationForError(error); + handleError(error, `Error while querying offers`, "ReadOffers"); throw error; } finally { clearMessage(); diff --git a/src/Common/dataAccess/readStoredProcedures.ts b/src/Common/dataAccess/readStoredProcedures.ts index fde9d7080..4f7c4b01b 100644 --- a/src/Common/dataAccess/readStoredProcedures.ts +++ b/src/Common/dataAccess/readStoredProcedures.ts @@ -1,10 +1,9 @@ import { AuthType } from "../../AuthType"; import { Resource, StoredProcedureDefinition } from "@azure/cosmos"; import { client } from "../CosmosClient"; +import { handleError } from "../ErrorHandlingUtils"; import { listSqlStoredProcedures } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { logConsoleError, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; -import { sendNotificationForError } from "./sendNotificationForError"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { userContext } from "../../UserContext"; export async function readStoredProcedures( @@ -31,9 +30,7 @@ export async function readStoredProcedures( .fetchAll(); return response?.resources; } catch (error) { - logConsoleError(`Failed to query stored procedures for container ${collectionId}: ${JSON.stringify(error)}`); - logError(JSON.stringify(error), "ReadStoredProcedures", error.code); - sendNotificationForError(error); + handleError(error, `Failed to query stored procedures for container ${collectionId}`, "ReadStoredProcedures"); throw error; } finally { clearMessage(); diff --git a/src/Common/dataAccess/readTriggers.ts b/src/Common/dataAccess/readTriggers.ts index 51e04799e..5216371c6 100644 --- a/src/Common/dataAccess/readTriggers.ts +++ b/src/Common/dataAccess/readTriggers.ts @@ -2,10 +2,9 @@ import { AuthType } from "../../AuthType"; import { Resource, TriggerDefinition } from "@azure/cosmos"; import { client } from "../CosmosClient"; import { listSqlTriggers } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { logConsoleError, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; -import { sendNotificationForError } from "./sendNotificationForError"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { userContext } from "../../UserContext"; +import { handleError } from "../ErrorHandlingUtils"; export async function readTriggers( databaseId: string, @@ -31,9 +30,7 @@ export async function readTriggers( .fetchAll(); return response?.resources; } catch (error) { - logConsoleError(`Failed to query triggers for container ${collectionId}: ${JSON.stringify(error)}`); - logError(JSON.stringify(error), "ReadTriggers", error.code); - sendNotificationForError(error); + handleError(error, `Failed to query triggers for container ${collectionId}`, "ReadTriggers"); throw error; } finally { clearMessage(); diff --git a/src/Common/dataAccess/readUserDefinedFunctions.ts b/src/Common/dataAccess/readUserDefinedFunctions.ts index 0c556c627..09b70d73e 100644 --- a/src/Common/dataAccess/readUserDefinedFunctions.ts +++ b/src/Common/dataAccess/readUserDefinedFunctions.ts @@ -1,10 +1,9 @@ import { AuthType } from "../../AuthType"; import { Resource, UserDefinedFunctionDefinition } from "@azure/cosmos"; import { client } from "../CosmosClient"; +import { handleError } from "../ErrorHandlingUtils"; import { listSqlUserDefinedFunctions } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { logConsoleError, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; -import { sendNotificationForError } from "./sendNotificationForError"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { userContext } from "../../UserContext"; export async function readUserDefinedFunctions( @@ -31,9 +30,11 @@ export async function readUserDefinedFunctions( .fetchAll(); return response?.resources; } catch (error) { - logConsoleError(`Failed to query user defined functions for container ${collectionId}: ${JSON.stringify(error)}`); - logError(JSON.stringify(error), "ReadUserDefinedFunctions", error.code); - sendNotificationForError(error); + handleError( + error, + `Failed to query user defined functions for container ${collectionId}`, + "ReadUserDefinedFunctions" + ); throw error; } finally { clearMessage(); diff --git a/src/Common/dataAccess/sendNotificationForError.ts b/src/Common/dataAccess/sendNotificationForError.ts index 102d1263a..8c7666991 100644 --- a/src/Common/dataAccess/sendNotificationForError.ts +++ b/src/Common/dataAccess/sendNotificationForError.ts @@ -2,7 +2,7 @@ import * as Constants from "../Constants"; import { sendMessage } from "../MessageHandler"; import { MessageTypes } from "../../Contracts/ExplorerContracts"; -interface CosmosError { +export interface CosmosError { code: number; message?: string; } diff --git a/src/Common/dataAccess/updateCollection.ts b/src/Common/dataAccess/updateCollection.ts index 0e276b7df..17d537870 100644 --- a/src/Common/dataAccess/updateCollection.ts +++ b/src/Common/dataAccess/updateCollection.ts @@ -23,10 +23,9 @@ import { getGremlinGraph } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; import { createUpdateTable, getTable } from "../../Utils/arm/generatedClients/2020-04-01/tableResources"; -import { logConsoleError, logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; +import { handleError } from "../ErrorHandlingUtils"; +import { logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { refreshCachedResources } from "../DataAccessUtilityBase"; -import { sendNotificationForError } from "./sendNotificationForError"; import { userContext } from "../../UserContext"; export async function updateCollection( @@ -58,9 +57,7 @@ export async function updateCollection( await refreshCachedResources(); return collection; } catch (error) { - logConsoleError(`Failed to update container ${collectionId}: ${JSON.stringify(error)}`); - logError(JSON.stringify(error), "UpdateCollection", error.code); - sendNotificationForError(error); + handleError(error, `Failed to update container ${collectionId}`, "UpdateCollection"); throw error; } finally { clearMessage(); diff --git a/src/Common/dataAccess/updateOffer.ts b/src/Common/dataAccess/updateOffer.ts index 7d7758381..5d003a023 100644 --- a/src/Common/dataAccess/updateOffer.ts +++ b/src/Common/dataAccess/updateOffer.ts @@ -6,12 +6,11 @@ import { OfferDefinition } from "@azure/cosmos"; import { RequestOptions } from "@azure/cosmos/dist-esm"; import { ThroughputSettingsUpdateParameters } from "../../Utils/arm/generatedClients/2020-04-01/types"; import { client } from "../CosmosClient"; -import { logConsoleError, logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; +import { handleError } from "../ErrorHandlingUtils"; +import { logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { readCollectionOffer } from "./readCollectionOffer"; import { readDatabaseOffer } from "./readDatabaseOffer"; import { refreshCachedOffers, refreshCachedResources } from "../DataAccessUtilityBase"; -import { sendNotificationForError } from "./sendNotificationForError"; import { updateSqlDatabaseThroughput, migrateSqlDatabaseToAutoscale, @@ -76,9 +75,7 @@ export const updateOffer = async (params: UpdateOfferParams): Promise => logConsoleInfo(`Successfully updated offer for ${offerResourceText}`); return updatedOffer; } catch (error) { - logConsoleError(`Error updating offer for ${offerResourceText}: ${JSON.stringify(error)}`); - logError(JSON.stringify(error), "UpdateCollection", error.code); - sendNotificationForError(error); + handleError(error, `Error updating offer for ${offerResourceText}`, "UpdateCollection"); throw error; } finally { clearMessage(); diff --git a/src/Common/dataAccess/updateStoredProcedure.ts b/src/Common/dataAccess/updateStoredProcedure.ts index 4e2884814..eddd72187 100644 --- a/src/Common/dataAccess/updateStoredProcedure.ts +++ b/src/Common/dataAccess/updateStoredProcedure.ts @@ -9,9 +9,8 @@ import { createUpdateSqlStoredProcedure, getSqlStoredProcedure } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { logConsoleError, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; -import { sendNotificationForError } from "./sendNotificationForError"; +import { handleError } from "../ErrorHandlingUtils"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { userContext } from "../../UserContext"; export async function updateStoredProcedure( @@ -60,10 +59,7 @@ export async function updateStoredProcedure( .replace(storedProcedure); return response?.resource; } catch (error) { - const errorMessage = error.code === "NotFound" ? `${storedProcedure.id} does not exist.` : JSON.stringify(error); - logConsoleError(`Error while updating stored procedure ${storedProcedure.id}:\n ${errorMessage}`); - logError(errorMessage, "UpdateStoredProcedure", error.code); - sendNotificationForError(error); + handleError(error, `Error while updating stored procedure ${storedProcedure.id}`, "UpdateStoredProcedure"); throw error; } finally { clearMessage(); diff --git a/src/Common/dataAccess/updateTrigger.ts b/src/Common/dataAccess/updateTrigger.ts index 0f6c6ef08..38f2dcebb 100644 --- a/src/Common/dataAccess/updateTrigger.ts +++ b/src/Common/dataAccess/updateTrigger.ts @@ -6,9 +6,8 @@ import { import { TriggerDefinition } from "@azure/cosmos"; import { client } from "../CosmosClient"; import { createUpdateSqlTrigger, getSqlTrigger } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { logConsoleError, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; -import { sendNotificationForError } from "./sendNotificationForError"; +import { handleError } from "../ErrorHandlingUtils"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { userContext } from "../../UserContext"; export async function updateTrigger( @@ -57,10 +56,7 @@ export async function updateTrigger( .replace(trigger); return response?.resource; } catch (error) { - const errorMessage = error.code === "NotFound" ? `${trigger.id} does not exist.` : JSON.stringify(error); - logConsoleError(`Error while updating trigger ${trigger.id}:\n ${errorMessage}`); - logError(errorMessage, "UpdateTrigger", error.code); - sendNotificationForError(error); + handleError(error, `Error while updating trigger ${trigger.id}`, "UpdateTrigger"); throw error; } finally { clearMessage(); diff --git a/src/Common/dataAccess/updateUserDefinedFunction.ts b/src/Common/dataAccess/updateUserDefinedFunction.ts index bb5c43d54..d81e95d85 100644 --- a/src/Common/dataAccess/updateUserDefinedFunction.ts +++ b/src/Common/dataAccess/updateUserDefinedFunction.ts @@ -9,9 +9,8 @@ import { createUpdateSqlUserDefinedFunction, getSqlUserDefinedFunction } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { logConsoleError, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { logError } from "../Logger"; -import { sendNotificationForError } from "./sendNotificationForError"; +import { handleError } from "../ErrorHandlingUtils"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { userContext } from "../../UserContext"; export async function updateUserDefinedFunction( @@ -60,11 +59,11 @@ export async function updateUserDefinedFunction( .replace(userDefinedFunction); return response?.resource; } catch (error) { - const errorMessage = - error.code === "NotFound" ? `${userDefinedFunction.id} does not exist.` : JSON.stringify(error); - logConsoleError(`Error while updating user defined function ${userDefinedFunction.id}:\n ${errorMessage}`); - logError(errorMessage, "UpdateUserupdateUserDefinedFunction", error.code); - sendNotificationForError(error); + handleError( + error, + `Error while updating user defined function ${userDefinedFunction.id}`, + "UpdateUserupdateUserDefinedFunction" + ); throw error; } finally { clearMessage(); diff --git a/src/Explorer/Explorer.ts b/src/Explorer/Explorer.ts index 536702a84..517bc7551 100644 --- a/src/Explorer/Explorer.ts +++ b/src/Explorer/Explorer.ts @@ -1120,7 +1120,7 @@ export default class Explorer { ); this.renewExplorerShareAccess(this, this.tokenForRenewal()) .fail((error: any) => { - const stringifiedError: string = JSON.stringify(error); + const stringifiedError: string = error.message; this.renewTokenError("Invalid connection string specified"); NotificationConsoleUtils.logConsoleMessage( ConsoleDataType.Error, @@ -1149,7 +1149,7 @@ export default class Explorer { NotificationConsoleUtils.clearInProgressMessageWithId(id); NotificationConsoleUtils.logConsoleMessage( ConsoleDataType.Error, - `Failed to generate share url: ${JSON.stringify(error)}` + `Failed to generate share url: ${error.message}` ); console.error(error); } @@ -1174,10 +1174,7 @@ export default class Explorer { deferred.resolve(); }, (error: any) => { - NotificationConsoleUtils.logConsoleMessage( - ConsoleDataType.Error, - `Failed to connect: ${JSON.stringify(error)}` - ); + NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, `Failed to connect: ${error.message}`); deferred.reject(error); } ) @@ -1457,13 +1454,13 @@ export default class Explorer { databaseAccountName: this.databaseAccount().name, defaultExperience: this.defaultExperience(), dataExplorerArea: Constants.Areas.ResourceTree, - error: JSON.stringify(error) + error: error.message }, startKey ); NotificationConsoleUtils.logConsoleMessage( ConsoleDataType.Error, - `Error while refreshing databases: ${JSON.stringify(error)}` + `Error while refreshing databases: ${error.message}` ); } ); @@ -1533,7 +1530,7 @@ export default class Explorer { this.isRefreshingExplorer(false); NotificationConsoleUtils.logConsoleMessage( ConsoleDataType.Error, - `Error while refreshing data: ${JSON.stringify(error)}` + `Error while refreshing data: ${error.message}` ); TelemetryProcessor.traceFailure( Action.LoadDatabases, @@ -1600,7 +1597,7 @@ export default class Explorer { return Promise.all(sparkPromises).then(() => workspaceItems); } catch (error) { Logger.logError(error, "Explorer/this._arcadiaManager.listWorkspacesAsync"); - NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, JSON.stringify(error)); + NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, error.message); return Promise.resolve([]); } } @@ -1638,7 +1635,7 @@ export default class Explorer { Logger.logError(error, "initNotebooks/getNotebookConnectionInfoAsync"); NotificationConsoleUtils.logConsoleMessage( ConsoleDataType.Error, - `Failed to get notebook workspace connection info: ${JSON.stringify(error)}` + `Failed to get notebook workspace connection info: ${error.message}` ); throw error; } finally { @@ -1715,7 +1712,7 @@ export default class Explorer { } } catch (error) { Logger.logError(error, "Explorer/ensureNotebookWorkspaceRunning"); - NotificationConsoleUtils.logConsoleError(`Failed to initialize notebook workspace: ${JSON.stringify(error)}`); + NotificationConsoleUtils.logConsoleError(`Failed to initialize notebook workspace: ${error.message}`); } finally { clearMessage && clearMessage(); } @@ -2093,7 +2090,7 @@ export default class Explorer { databaseAccountName: this.databaseAccount() && this.databaseAccount().name, defaultExperience: this.defaultExperience && this.defaultExperience(), dataExplorerArea: Constants.Areas.ResourceTree, - trace: JSON.stringify(error) + trace: error.message }, startKey ); @@ -2555,7 +2552,7 @@ export default class Explorer { (error: any) => { NotificationConsoleUtils.logConsoleMessage( ConsoleDataType.Error, - `Could not download notebook ${JSON.stringify(error)}` + `Could not download notebook ${error.message}` ); clearMessage(); diff --git a/src/Explorer/Graph/GraphExplorerComponent/GraphExplorer.tsx b/src/Explorer/Graph/GraphExplorerComponent/GraphExplorer.tsx index c613658c5..bbe2982b7 100644 --- a/src/Explorer/Graph/GraphExplorerComponent/GraphExplorer.tsx +++ b/src/Explorer/Graph/GraphExplorerComponent/GraphExplorer.tsx @@ -892,7 +892,7 @@ export class GraphExplorer extends React.Component (this.queryTotalRequestCharge = result.requestCharge), (error: any) => { - const errorMsg = `Failure in submitting query: ${query}: ${JSON.stringify(error)}`; + const errorMsg = `Failure in submitting query: ${query}: ${error.message}`; GraphExplorer.reportToConsole(ConsoleDataType.Error, errorMsg); this.setState({ filterQueryError: errorMsg @@ -1826,7 +1826,7 @@ export class GraphExplorer extends React.Component this.processGremlinQueryResults(result)) .catch((error: any) => { - const errorMsg = `Failed to process query result: ${JSON.stringify(error)}`; + const errorMsg = `Failed to process query result: ${error.message}`; GraphExplorer.reportToConsole(ConsoleDataType.Error, errorMsg); this.setState({ filterQueryError: errorMsg diff --git a/src/Explorer/Graph/GraphExplorerComponent/GremlinClient.ts b/src/Explorer/Graph/GraphExplorerComponent/GremlinClient.ts index e872dddda..05627e2bf 100644 --- a/src/Explorer/Graph/GraphExplorerComponent/GremlinClient.ts +++ b/src/Explorer/Graph/GraphExplorerComponent/GremlinClient.ts @@ -57,9 +57,9 @@ export class GremlinClient { this.flushResult(result.requestId); } }, - failureCallback: (result: Result, error: string) => { + failureCallback: (result: Result, error: any) => { if (typeof error !== "string") { - error = JSON.stringify(error); + error = error.message; } const requestId = result.requestId; diff --git a/src/Explorer/Notebook/NotebookComponent/store.ts b/src/Explorer/Notebook/NotebookComponent/store.ts index 924b81e2b..3f6b6e3eb 100644 --- a/src/Explorer/Notebook/NotebookComponent/store.ts +++ b/src/Explorer/Notebook/NotebookComponent/store.ts @@ -47,7 +47,7 @@ export default function configureStore( onTraceFailure(title, `${error.message} ${JSON.stringify(error.stack)}`); console.error(error); } else { - onTraceFailure(title, JSON.stringify(error)); + onTraceFailure(title, error.message); } }; diff --git a/src/Explorer/Panes/BrowseQueriesPane.ts b/src/Explorer/Panes/BrowseQueriesPane.ts index fc2b2e466..5c194c970 100644 --- a/src/Explorer/Panes/BrowseQueriesPane.ts +++ b/src/Explorer/Panes/BrowseQueriesPane.ts @@ -70,8 +70,7 @@ export class BrowseQueriesPane extends ContextualPaneBase { }, startKey ); - this.formErrors("Failed to setup a collection for saved queries"); - this.formErrors(`Failed to setup a collection for saved queries: ${JSON.stringify(error)}`); + this.formErrors(`Failed to setup a collection for saved queries: ${error.message}`); } finally { this.isExecuting(false); } diff --git a/src/Explorer/Panes/RenewAdHocAccessPane.ts b/src/Explorer/Panes/RenewAdHocAccessPane.ts index eeb1eb6f6..440df54ee 100644 --- a/src/Explorer/Panes/RenewAdHocAccessPane.ts +++ b/src/Explorer/Panes/RenewAdHocAccessPane.ts @@ -82,7 +82,7 @@ export class RenewAdHocAccessPane extends ContextualPaneBase { this.container .renewShareAccess(this.accessKey()) .fail((error: any) => { - const errorMessage: string = JSON.stringify(error); + const errorMessage: string = error.message; NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, `Failed to connect: ${errorMessage}`); this.formErrors(errorMessage); this.formErrorsDetails(errorMessage); diff --git a/src/Explorer/Panes/SaveQueryPane.ts b/src/Explorer/Panes/SaveQueryPane.ts index b5056d521..4d249d6a9 100644 --- a/src/Explorer/Panes/SaveQueryPane.ts +++ b/src/Explorer/Panes/SaveQueryPane.ts @@ -88,7 +88,7 @@ export class SaveQueryPane extends ContextualPaneBase { (error: any) => { this.isExecuting(false); if (typeof error != "string") { - error = JSON.stringify(error); + error = error.message; } this.formErrors("Failed to save query"); this.formErrorsDetails(`Failed to save query: ${error}`); @@ -143,7 +143,7 @@ export class SaveQueryPane extends ContextualPaneBase { startKey ); this.formErrors("Failed to setup a container for saved queries"); - this.formErrors(`Failed to setup a container for saved queries: ${JSON.stringify(error)}`); + this.formErrors(`Failed to setup a container for saved queries: ${error.message}`); } finally { this.isExecuting(false); } diff --git a/src/Explorer/Panes/SetupNotebooksPane.ts b/src/Explorer/Panes/SetupNotebooksPane.ts index 29c84d859..6a8e56dc9 100644 --- a/src/Explorer/Panes/SetupNotebooksPane.ts +++ b/src/Explorer/Panes/SetupNotebooksPane.ts @@ -85,7 +85,7 @@ export class SetupNotebooksPane extends ContextualPaneBase { "Successfully created a default notebook workspace for the account" ); } catch (error) { - const errorMessage = typeof error == "string" ? error : JSON.stringify(error); + const errorMessage = typeof error == "string" ? error : error.message; TelemetryProcessor.traceFailure( Action.CreateNotebookWorkspace, { diff --git a/src/Explorer/Tabs/DocumentsTab.ts b/src/Explorer/Tabs/DocumentsTab.ts index 3cf59321d..1779e10a0 100644 --- a/src/Explorer/Tabs/DocumentsTab.ts +++ b/src/Explorer/Tabs/DocumentsTab.ts @@ -776,7 +776,7 @@ export default class DocumentsTab extends TabsBase { this.isExecutionError(true); NotificationConsoleUtils.logConsoleMessage( ConsoleDataType.Error, - typeof error === "string" ? error : JSON.stringify(error) + typeof error === "string" ? error : error.message ); if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) { TelemetryProcessor.traceFailure( diff --git a/src/Explorer/Tree/Collection.ts b/src/Explorer/Tree/Collection.ts index 1d451cbef..04f99bde1 100644 --- a/src/Explorer/Tree/Collection.ts +++ b/src/Explorer/Tree/Collection.ts @@ -619,7 +619,7 @@ export default class Collection implements ViewModels.Collection { ); NotificationConsoleUtils.logConsoleMessage( ConsoleDataType.Error, - `Error while fetching container settings for container ${this.id()}: ${JSON.stringify(error)}` + `Error while fetching container settings for container ${this.id()}: ${error.message}` ); throw error; } @@ -841,7 +841,7 @@ export default class Collection implements ViewModels.Collection { collectionName: this.id(), defaultExperience: this.container.defaultExperience(), dataExplorerArea: Constants.Areas.ResourceTree, - error: typeof error === "string" ? error : JSON.stringify(error) + error: typeof error === "string" ? error : error.message }); } ); @@ -900,7 +900,7 @@ export default class Collection implements ViewModels.Collection { collectionName: this.id(), defaultExperience: this.container.defaultExperience(), dataExplorerArea: Constants.Areas.ResourceTree, - error: typeof error === "string" ? error : JSON.stringify(error) + error: typeof error === "string" ? error : error.message }); } ); @@ -960,7 +960,7 @@ export default class Collection implements ViewModels.Collection { collectionName: this.id(), defaultExperience: this.container.defaultExperience(), dataExplorerArea: Constants.Areas.ResourceTree, - error: typeof error === "string" ? error : JSON.stringify(error) + error: typeof error === "string" ? error : error.message }); } ); @@ -1157,7 +1157,7 @@ export default class Collection implements ViewModels.Collection { }, error => { record.numFailed++; - record.errors = [...record.errors, JSON.stringify(error)]; + record.errors = [...record.errors, error.message]; return Q.resolve(); } ); @@ -1210,7 +1210,7 @@ export default class Collection implements ViewModels.Collection { (error: any) => { Logger.logError( JSON.stringify({ - error: JSON.stringify(error), + error: error.message, accountName: this.container && this.container.databaseAccount(), databaseName: this.databaseId, collectionName: this.id() diff --git a/src/Explorer/Tree/Database.ts b/src/Explorer/Tree/Database.ts index 63bcc4f2b..faa33d406 100644 --- a/src/Explorer/Tree/Database.ts +++ b/src/Explorer/Tree/Database.ts @@ -103,7 +103,7 @@ export default class Database implements ViewModels.Database { ); NotificationConsoleUtils.logConsoleMessage( ConsoleDataType.Error, - `Error while fetching database settings for database ${this.id()}: ${JSON.stringify(error)}` + `Error while fetching database settings for database ${this.id()}: ${error.message}` ); throw error; } @@ -239,7 +239,7 @@ export default class Database implements ViewModels.Database { (error: any) => { Logger.logError( JSON.stringify({ - error: JSON.stringify(error), + error: error.message, accountName: this.container && this.container.databaseAccount(), databaseName: this.id(), collectionName: this.id() diff --git a/src/Explorer/Tree/StoredProcedure.ts b/src/Explorer/Tree/StoredProcedure.ts index 9b3aa9a13..f2db0b577 100644 --- a/src/Explorer/Tree/StoredProcedure.ts +++ b/src/Explorer/Tree/StoredProcedure.ts @@ -158,7 +158,7 @@ export default class StoredProcedure { sprocTab.onExecuteSprocsResult(result, result.scriptLogs); }, (error: any) => { - sprocTab.onExecuteSprocsError(JSON.stringify(error)); + sprocTab.onExecuteSprocsError(error.message); } ) .finally(() => { diff --git a/src/GitHub/GitHubContentProvider.ts b/src/GitHub/GitHubContentProvider.ts index 899268704..9d6dcc82b 100644 --- a/src/GitHub/GitHubContentProvider.ts +++ b/src/GitHub/GitHubContentProvider.ts @@ -423,7 +423,7 @@ export class GitHubContentProvider implements IContentProvider { request: {}, status: error.errno, response: error, - responseText: JSON.stringify(error), + responseText: error.message, responseType: "json" }; } diff --git a/src/HostedExplorer.ts b/src/HostedExplorer.ts index 23c501721..77024a87c 100644 --- a/src/HostedExplorer.ts +++ b/src/HostedExplorer.ts @@ -514,7 +514,7 @@ class HostedExplorer { actionType: ActionType.TransmitCachedData, message: { id: message && message.id, - error: JSON.stringify(error) + error: error.message } }); } @@ -1008,7 +1008,7 @@ class HostedExplorer { return accounts; } catch (error) { - this._logConsoleMessage(ConsoleDataType.Error, `Failed to fetch accounts: ${JSON.stringify(error)}`); + this._logConsoleMessage(ConsoleDataType.Error, `Failed to fetch accounts: ${error.message}`); this._clearInProgressMessageWithId(id); throw error; @@ -1047,7 +1047,7 @@ class HostedExplorer { displayText: "Error loading account" }); this._updateLoadingStatusText(`Failed to load selected account: ${newAccount.name}`); - this._logConsoleMessage(ConsoleDataType.Error, `Failed to connect: ${JSON.stringify(error)}`); + this._logConsoleMessage(ConsoleDataType.Error, `Failed to connect: ${error.message}`); this._clearInProgressMessageWithId(id); throw error; } diff --git a/src/Platform/Hosted/Main.ts b/src/Platform/Hosted/Main.ts index f7a0e1eb8..d424704f4 100644 --- a/src/Platform/Hosted/Main.ts +++ b/src/Platform/Hosted/Main.ts @@ -245,7 +245,7 @@ export default class Main { ); }, (error: any) => { - deferred.reject(`Failed to generate encrypted token: ${JSON.stringify(error)}`); + deferred.reject(`Failed to generate encrypted token: ${error.message}`); } ); diff --git a/src/workers/upload/index.ts b/src/workers/upload/index.ts index 4fa3f9e84..7f5172db3 100644 --- a/src/workers/upload/index.ts +++ b/src/workers/upload/index.ts @@ -93,7 +93,7 @@ function createDocumentsFromFile(fileName: string, documentContent: string): voi }) .catch(error => { console.error(error); - recordUploadDetailErrorForFile(fileName, JSON.stringify(error)); + recordUploadDetailErrorForFile(fileName, error.message); numUploadsFailed++; }) .finally(() => {