Fix error handling in DE (#294)

- Replaced `JSON.stringify(error)` with `error.message`
- Created `ErrorHandlingUtils` and moved all error logging actions in there
This commit is contained in:
victor-meng
2020-10-21 14:28:30 -07:00
committed by GitHub
parent e09730d782
commit 24b5b754ca
46 changed files with 187 additions and 265 deletions

View File

@@ -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();

View File

@@ -892,7 +892,7 @@ export class GraphExplorer extends React.Component<GraphExplorerProps, GraphExpl
backendPromise.then(
(result: UserQueryResult) => (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<GraphExplorerProps, GraphExpl
promise
.then((result: GremlinClient.GremlinRequestResult) => 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

View File

@@ -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;

View File

@@ -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);
}
};

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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,
{

View File

@@ -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(

View File

@@ -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()

View File

@@ -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()

View File

@@ -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(() => {