Skip to content

Commit a6a8806

Browse files
author
Arvid Paeglit
committed
improved error handling
1 parent 6e6a20b commit a6a8806

5 files changed

Lines changed: 41 additions & 62 deletions

File tree

src/deepcode/constants/statusCodes.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/deepcode/lib/modules/BundlesModule.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { BundlesModuleInterface } from "../../../interfaces/DeepCodeInterfaces";
55

66
import LoginModule from "../../lib/modules/LoginModule";
77
import { DEEPCODE_ANALYSIS_STATUS, DEEPCODE_CONTEXT } from "../../constants/views";
8-
import { errorsLogs } from "../../messages/errorsServerLogMessages";
9-
import { statusCodes } from '../../constants/statusCodes';
8+
import { errorsLogs } from '../../messages/errorsServerLogMessages';
109

1110
import { analyzeFolders, extendAnalysis } from '@deepcode/tsc';
1211

src/deepcode/lib/modules/DeepCodeLib.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export default class DeepCodeLib extends BundlesModule implements DeepCodeLibInt
4040
return;
4141
}
4242

43+
await this.setContext(DEEPCODE_CONTEXT.ERROR, false);
44+
this.resetTransientErrors();
45+
await this.setLoadingBadge(false);
46+
4347
if (!this.token) {
4448
await this.checkSession();
4549
return;
@@ -51,15 +55,9 @@ export default class DeepCodeLib extends BundlesModule implements DeepCodeLibInt
5155
return;
5256
}
5357

54-
// TODO: handle wrong/expired API Key issue
5558
try {
56-
console.log('DeepCode: starting execution pipeline');
57-
await this.setContext(DEEPCODE_CONTEXT.ERROR, false);
58-
this.resetTransientErrors();
59-
await this.setLoadingBadge(false);
6059
await this.startAnalysis();
6160
} catch (err) {
62-
console.log('failed debounced function');
6361
await this.processError(err, {
6462
message: errorsLogs.failedExecutionDebounce,
6563
});

src/deepcode/lib/modules/ReportModule.ts

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { ReportModuleInterface, errorType } from "../../../interfaces/DeepCodeInterfaces";
2-
import BaseDeepCodeModule from "./BaseDeepCodeModule";
3-
import { statusCodes } from "../../constants/statusCodes";
2+
import BaseDeepCodeModule from './BaseDeepCodeModule';
43
import { errorsLogs } from "../../messages/errorsServerLogMessages";
54
import { TELEMETRY_EVENTS } from "../../constants/telemetry";
65
import { DEEPCODE_CONTEXT, DEEPCODE_ERROR_CODES } from "../../constants/views";
76
import { MAX_CONNECTION_RETRIES, CONNECTION_ERROR_RETRY_INTERVAL } from "../../constants/general";
87

9-
import { reportEvent, reportError } from '@deepcode/tsc';
8+
import { reportEvent, reportError, constants } from '@deepcode/tsc';
109

1110
abstract class ReportModule extends BaseDeepCodeModule implements ReportModuleInterface {
1211
private transientErrors = 0;
@@ -84,45 +83,43 @@ abstract class ReportModule extends BaseDeepCodeModule implements ReportModuleIn
8483
private async processErrorInternal(error: errorType, options: { [key: string]: any } = {}): Promise<void> {
8584
// console.error(`DeepCode error handler: ${JSON.stringify(error)}`);
8685

87-
if (error.error) {
88-
const { code, message } = error.error;
89-
// TODO: move it to 'tsc'
90-
if (code === 'ENOTFOUND' && message === 'getaddrinfo ENOTFOUND www.deepcode.ai') {
91-
return this.connectionErrorHandler();
92-
}
93-
}
94-
95-
if (error.errno) {
96-
if (error.errno === 'ECONNREFUSED') return this.connectionErrorHandler();
86+
const defaultErrorHandler = async () => {
9787
await this.sendErrorToServer(error, options);
98-
return this.generalErrorHandler();
99-
}
88+
await this.generalErrorHandler();
89+
};
10090

101-
const {
102-
unauthorizedUser,
103-
unauthorizedContent,
104-
unauthorizedBundleAccess,
105-
notFound,
106-
serverError,
107-
badGateway,
108-
serviceUnavailable,
109-
timeout,
110-
} = statusCodes;
111-
112-
switch (error.statusCode) {
113-
case serverError:
114-
case badGateway:
115-
case serviceUnavailable:
116-
case timeout:
91+
const errorHandlers: { [P in constants.ErrorCodes]: () => Promise<void> } = {
92+
[constants.ErrorCodes.serverError]: defaultErrorHandler,
93+
[constants.ErrorCodes.badGateway]: async () => {
94+
return this.connectionErrorHandler();
95+
},
96+
[constants.ErrorCodes.serviceUnavailable]: async () => {
97+
return this.connectionErrorHandler();
98+
},
99+
[constants.ErrorCodes.timeout]: async () => {
100+
return this.connectionErrorHandler();
101+
},
102+
[constants.ErrorCodes.dnsNotFound]: async () => {
103+
return this.connectionErrorHandler();
104+
},
105+
[constants.ErrorCodes.connectionRefused]: async () => {
117106
return this.connectionErrorHandler();
118-
case unauthorizedContent:
119-
case unauthorizedBundleAccess:
120-
case unauthorizedUser:
107+
},
108+
[constants.ErrorCodes.loginInProgress]: async () => {},
109+
[constants.ErrorCodes.unauthorizedContent]: async () => {},
110+
[constants.ErrorCodes.unauthorizedUser]: async () => {
121111
return this.authenticationErrorHandler();
122-
case notFound:
123-
default:
124-
await this.sendErrorToServer(error, options);
125-
return this.generalErrorHandler();
112+
},
113+
[constants.ErrorCodes.unauthorizedBundleAccess]: async () => {},
114+
[constants.ErrorCodes.notFound]: async () => {},
115+
[constants.ErrorCodes.bigPayload]: async () => {},
116+
};
117+
118+
const errorHandler = errorHandlers[error.statusCode];
119+
if (errorHandler) {
120+
await errorHandler();
121+
} else {
122+
await defaultErrorHandler();
126123
}
127124
}
128125

yalc.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "v1",
33
"packages": {
44
"@deepcode/tsc": {
5-
"signature": "8dfc036aed29fdb3ecb8bafc17ff7b69",
5+
"signature": "4b6fe85954a7581475117ad29cab1fb9",
66
"file": true
77
}
88
}

0 commit comments

Comments
 (0)