From 535f6806fb0bcb97b1abaf78784ce0fa1235c5d3 Mon Sep 17 00:00:00 2001 From: Lorenzo Donati Date: Tue, 2 Jun 2020 17:06:22 +0200 Subject: [PATCH 1/2] Added reportError feature. --- src/deepcode/http/requests.ts | 11 +++---- .../lib/errorHandler/DeepCodeErrorHandler.ts | 30 +++++++++++-------- src/interfaces/DeepCodeInterfaces.ts | 2 +- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/deepcode/http/requests.ts b/src/deepcode/http/requests.ts index a79c39a6..11fd55ab 100644 --- a/src/deepcode/http/requests.ts +++ b/src/deepcode/http/requests.ts @@ -8,7 +8,7 @@ import { IDE_NAME } from "../constants/general"; const AI = new ServiceAI(); const http = { - + login(baseURL: string, source: string = IDE_NAME): Promise { return AI.startSession({ baseURL, source }); }, @@ -35,10 +35,11 @@ const http = { }); }, - // TODO: when API package will implement such functionality - // we would have the possibility to send an error to server - async sendError(body: any): Promise { - return Promise.resolve(); + async sendError(baseURL: string, options: object): Promise { + return AI.reportError({ + baseURL, + ...options + }); } }; diff --git a/src/deepcode/lib/errorHandler/DeepCodeErrorHandler.ts b/src/deepcode/lib/errorHandler/DeepCodeErrorHandler.ts index 15f385f5..bfab4ac9 100644 --- a/src/deepcode/lib/errorHandler/DeepCodeErrorHandler.ts +++ b/src/deepcode/lib/errorHandler/DeepCodeErrorHandler.ts @@ -29,7 +29,7 @@ class DeepCodeErrorHandler implements DeepCode.ErrorHandlerInterface { private async serverErrorHandler(extension: DeepCode.ExtensionInterface | any): Promise { const { msg } = deepCodeMessages.noConnection; vscode.window.showErrorMessage(msg); - + setTimeout(async () => { startDeepCodeCommand(); }, 5000); @@ -86,19 +86,23 @@ class DeepCodeErrorHandler implements DeepCode.ErrorHandlerInterface { error: DeepCode.errorType, options: { [key: string]: any } ): Promise { - if (process.env.NODE_ENV === "production") { + if (process.env.NODE_ENV === "production" || extension.baseURL !== extension.defaultBaseURL) { // please disable request sending in dev mode to avoid unnecessary reports to server - await http.sendError({ - //for testing edpoint use source: 'test' - source: IDE_NAME, - type: `${error.statusCode || ""} ${error.name || ""}`.trim(), - errorTrace: JSON.stringify(error), - message: options.message || errorsLogs.undefinedError, - ...(extension.token && { sessionToken: extension.token }), - ...(options.endpoint && { path: options.endpoint }), - ...(options.bundleId && { bundleId: options.bundleId }), - ...(options.data && { data: options.data }) - }); + await http.sendError( + extension.baseURL, + { + source: extension.source, + type: `${error.statusCode || ""} ${error.name || ""}`.trim(), + message: options.message || errorsLogs.undefinedError, + ...(extension.token && { sessionToken: extension.token }), + ...(options.endpoint && { path: options.endpoint }), + ...(options.bundleId && { bundleId: options.bundleId }), + data: { + errorTrace: JSON.stringify(error), + ...options.data + } + } + ); } } diff --git a/src/interfaces/DeepCodeInterfaces.ts b/src/interfaces/DeepCodeInterfaces.ts index 4812ac6d..f28ce700 100644 --- a/src/interfaces/DeepCodeInterfaces.ts +++ b/src/interfaces/DeepCodeInterfaces.ts @@ -174,7 +174,7 @@ namespace DeepCode { extension: ExtensionInterface | any, error: errorType, options?: { [key: string]: any } - ): void; + ): Promise; } export interface BaseDeepCodeModuleInterface { From 2728f83940833f35a76d33fdac948e3e77580f6d Mon Sep 17 00:00:00 2001 From: Lorenzo Donati Date: Tue, 2 Jun 2020 17:09:57 +0200 Subject: [PATCH 2/2] Required new tsc version. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5a824fdb..6519a41a 100644 --- a/package.json +++ b/package.json @@ -103,6 +103,6 @@ "ignore": "^5.1.4", "mz": "^2.7.0", "open": "^7.0.0", - "@deepcode/tsc": "^1.1.0" + "@deepcode/tsc": "^1.2.0" } }