@@ -4,8 +4,8 @@ import BaseDeepCodeModule from "./BaseDeepCodeModule";
44import { statusCodes } from "../../constants/statusCodes" ;
55import { errorsLogs } from "../../messages/errorsServerLogMessages" ;
66import { setContext } from "../../utils/vscodeCommandsUtils" ;
7- import { DEEPCODE_CONTEXT , DEEPCODE_ERROR_CODES } from "../../constants/views" ;
8- import { MAX_CONNECTION_RETRIES } from "../../constants/general" ;
7+ import { DEEPCODE_CONTEXT , DEEPCODE_ERROR_CODES , DEEPCODE_VIEW_ERROR } from "../../constants/views" ;
8+ import { MAX_CONNECTION_RETRIES , CONNECTION_ERROR_RETRY_INTERVAL } from "../../constants/general" ;
99
1010abstract class ReportModule extends BaseDeepCodeModule implements DeepCode . ReportModuleInterface {
1111 private transientErrors = 0 ;
@@ -45,7 +45,7 @@ abstract class ReportModule extends BaseDeepCodeModule implements DeepCode.Repor
4545 ...options
4646 } ) ;
4747 } catch ( error ) {
48- this . processError ( error , {
48+ await this . processError ( error , {
4949 message : errorsLogs . sendEvent ,
5050 data : {
5151 event,
@@ -60,6 +60,17 @@ abstract class ReportModule extends BaseDeepCodeModule implements DeepCode.Repor
6060 async processError (
6161 error : DeepCode . errorType ,
6262 options : { [ key : string ] : any } = { }
63+ ) : Promise < void > {
64+ // We don't want to have unhandled rejections around, so if it
65+ // happens in the error handler we just log it to console.error
66+ return this . processErrorInternal ( error , options ) . catch ( ( error ) =>
67+ console . error ( "DeepCode error handler failed with error:" , error )
68+ ) ;
69+ }
70+
71+ private async processErrorInternal (
72+ error : DeepCode . errorType ,
73+ options : { [ key : string ] : any } = { }
6374 ) : Promise < void > {
6475 console . error ( "DeepCode error handler:" , error ) ;
6576
@@ -89,24 +100,25 @@ abstract class ReportModule extends BaseDeepCodeModule implements DeepCode.Repor
89100 } = statusCodes ;
90101
91102 switch ( error . statusCode ) {
92- case unauthorizedContent :
93- case unauthorizedBundleAccess :
94103 case serverError :
95104 case badGateway :
96105 case serviceUnavailable :
97106 case timeout :
98- await this . connectionErrorHandler ( ) ;
107+ return this . connectionErrorHandler ( ) ;
108+ case unauthorizedContent :
109+ case unauthorizedBundleAccess :
99110 case unauthorizedUser :
100111 case notFound :
101112 default :
102113 await this . sendErrorToServer ( error , options ) ;
103- await this . generalErrorHandler ( ) ;
114+ return this . generalErrorHandler ( ) ;
104115 }
105116 }
106117
107118 private async generalErrorHandler ( ) : Promise < void > {
108119 this . transientErrors = 0 ;
109120 await setContext ( DEEPCODE_CONTEXT . ERROR , DEEPCODE_ERROR_CODES . BLOCKING ) ;
121+ await this . setLoadingBadge ( DEEPCODE_VIEW_ERROR ) ;
110122 }
111123
112124 private async connectionErrorHandler ( ) : Promise < void > {
@@ -118,7 +130,7 @@ abstract class ReportModule extends BaseDeepCodeModule implements DeepCode.Repor
118130 this . startExtension ( ) . catch ( ( err ) => this . processError ( err , {
119131 message : errorsLogs . failedExecutionTransient ,
120132 } ) ) ;
121- } , 5000 ) ;
133+ } , CONNECTION_ERROR_RETRY_INTERVAL ) ;
122134 }
123135
124136 private async sendErrorToServer (
0 commit comments