@@ -92,14 +92,24 @@ export class ErrorHandlerService {
9292 this . glitchTipEnabled = this . shouldEnableGlitchTip ( ) ;
9393 if ( ! this . glitchTipEnabled ) return ;
9494 const glitchTipDsn = this . envService . getGlitchTipDsn ( ) ;
95- Sentry . init ( {
96- dsn : glitchTipDsn ,
97- integrations : [ Sentry . browserTracingIntegration ( ) ] ,
98- tracesSampleRate : 1.0 ,
99- release : __APP_VERSION__ ,
100- environment : this . envService . getEnvironmentType ( ) ,
101- denyUrls : [ 'localhost' ] ,
102- } ) ;
95+ try {
96+ Sentry . init ( {
97+ dsn : glitchTipDsn ,
98+ integrations : [ Sentry . browserTracingIntegration ( ) ] ,
99+ tracesSampleRate : 1.0 ,
100+ release : __APP_VERSION__ ,
101+ environment : this . envService . getEnvironmentType ( ) ,
102+ denyUrls : [ 'localhost' ] ,
103+ } ) ;
104+ } catch ( e ) {
105+ this . handleError ( {
106+ error : e ,
107+ message : 'Unable to initialize GlitchTip. Possibly due to adblock, invalid DSN, or user\'s privacy preferences' ,
108+ location : 'ErrorHandlerService.initializeGlitchTip' ,
109+ showToast : false ,
110+ } ) ;
111+ this . glitchTipEnabled = false ;
112+ }
103113 }
104114
105115 /* Gets the user ID from local storage (if available) */
@@ -165,6 +175,29 @@ export class ErrorHandlerService {
165175 return JSON . parse ( localStorage . getItem ( 'DL_error_log' ) || '[]' ) . reverse ( ) ;
166176 }
167177
178+ public initializeWindowCatching ( ) {
179+ if ( isPlatformBrowser ( this . platformId ) && typeof window !== 'undefined' ) {
180+ window . onerror = ( message , source , lineno , colno , error ) => {
181+ this . handleError ( {
182+ message : String ( message ) ,
183+ location : `window (${ source } :${ lineno } :${ colno } )` ,
184+ error,
185+ showToast : false ,
186+ } ) ;
187+ } ;
188+
189+ window . onunhandledrejection = ( event ) => {
190+ this . handleError ( {
191+ message : 'Unhandled Promise Rejection' ,
192+ location : 'window.onunhandledrejection' ,
193+ error : event . reason ,
194+ showToast : false ,
195+ } ) ;
196+ } ;
197+ }
198+
199+ }
200+
168201 public printInitialDetails ( ) : void {
169202 if ( ! isPlatformBrowser ( this . platformId ) ) return ;
170203 const environment = this . envService . getEnvironmentType ( ) ;
0 commit comments