Skip to content

Commit a854e6c

Browse files
committed
improved http error handling.
1 parent 684b16c commit a854e6c

4 files changed

Lines changed: 50 additions & 17 deletions

File tree

src/deepcode/lib/modules/BundlesModule.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,13 @@ abstract class BundlesModule extends LoginModule
134134

135135
// procesing filter list of files, acceptable for server
136136
public async createFilesFilterList(): Promise<void> {
137-
this.serverFilesFilterList = await http.getFilters(this.baseURL, this.token);
137+
try {
138+
this.serverFilesFilterList = await http.getFilters(this.baseURL, this.token);
139+
} catch (err) {
140+
this.processError(err, {
141+
message: errorsLogs.filtersFiles
142+
})
143+
}
138144
}
139145

140146
private terminateAnalysis(): void {
@@ -195,7 +201,11 @@ abstract class BundlesModule extends LoginModule
195201
this.onError(error);
196202
});
197203

198-
http.analyse(this.baseURL, this.token, path, this.files, removedFiles).catch((error) => this.onError(error));
204+
http.analyse(this.baseURL, this.token, path, this.files, removedFiles).catch(
205+
(error) => this.processError(error, {
206+
message: errorsLogs.analyse
207+
})
208+
);
199209
}
200210

201211
private async startCollectingFiles(

src/deepcode/lib/modules/LoginModule.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ abstract class LoginModule extends ReportModule implements DeepCode.LoginModuleI
3838
async checkSession(): Promise<boolean> {
3939
let validSession = false;
4040
if (this.token) {
41-
validSession = !!(await http.checkSession(this.baseURL, this.token));
41+
try {
42+
validSession = !!(await http.checkSession(this.baseURL, this.token));
43+
} catch (err) {
44+
this.processError(err, {
45+
message: errorsLogs.loginStatus
46+
});
47+
}
4248
}
4349
await setContext(DEEPCODE_CONTEXT.LOGGEDIN, validSession);
4450
return validSession;

src/deepcode/lib/modules/ReportModule.ts

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,37 @@ abstract class ReportModule extends BaseDeepCodeModule implements DeepCode.Repor
2424

2525
async sendError(options: {[key: string]: any}): Promise<void> {
2626
if (!this.shouldReport || !this.shouldReportErrors) return;
27-
await http.sendError(this.baseURL, {
28-
source: this.source,
29-
...(this.token && { sessionToken: this.token }),
30-
...options
31-
});
27+
try {
28+
await http.sendError(this.baseURL, {
29+
source: this.source,
30+
...(this.token && { sessionToken: this.token }),
31+
...options
32+
});
33+
} catch(error) {
34+
console.error(error);
35+
}
3236
}
3337

3438
async sendEvent(event: string, options: {[key: string]: any}): Promise<void> {
3539
if (!this.shouldReport || !this.shouldReportEvents) return;
36-
await http.sendEvent(this.baseURL, {
37-
type: event,
38-
source: this.source,
39-
...(this.token && { sessionToken: this.token }),
40-
...options
41-
});
40+
try {
41+
await http.sendEvent(this.baseURL, {
42+
type: event,
43+
source: this.source,
44+
...(this.token && { sessionToken: this.token }),
45+
...options
46+
});
47+
} catch(error) {
48+
this.processError(error, {
49+
message: errorsLogs.sendEvent,
50+
data: {
51+
event,
52+
source: this.source,
53+
...(this.token && { sessionToken: this.token }),
54+
...options
55+
},
56+
});
57+
}
4258
}
4359

4460
async processError(

src/deepcode/messages/errorsServerLogMessages.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const errorsLogs = {
22
login: "Login of new user has failed",
3-
// loginStatus: "Check login status of user has failed",
3+
loginStatus: "Failed to check user session on server",
44
filtersFiles: "Failed fetching filters files for bundles from server",
55
// createBundle: "Failed to create bundle on server",
66
// uploadFiles: "Failed to upload missing files in bundle to server",
@@ -9,7 +9,7 @@ export const errorsLogs = {
99
// `Failed fetching bundle status on server after ${attempts} attempts`,
1010
// extendBundle: "Failed to extend bundle on server with files",
1111
// failedStatusOfAnalysis: "Analysis results have status FAILED",
12-
// analyze: "Analysis request failed",
12+
analyse: "ServiceAI analyse request failed",
1313
failedAnalysis: "Failed executing analysis",
1414
failedServiceAI: "ServiceAI returned an error",
1515
failedExecution: "Failed extension pipeline execution",
@@ -21,7 +21,8 @@ export const errorsLogs = {
2121
updateReviewPositions:
2222
"Failed to update review results positions while editing file",
2323
errorReportFail: "Failed to send error report",
24-
modifiedFile: (type: string) => `Failed to handle file change of type ${type}`,
24+
modifiedFile: (type: string) => `Failed to handle changes on file of type ${type}`,
2525
// vscodeFileChanges: "Failed to process vscode file content changes",
2626
command: (type: string) => `Failed to execute ${type} command`,
27+
sendEvent: "Failed to send event to server",
2728
};

0 commit comments

Comments
 (0)