@@ -50,6 +50,12 @@ if (!isLoggerSet()) {
5050 * @copyright CodeX
5151 */
5252export default class Catcher {
53+
54+ /**
55+ * Catcher Type
56+ */
57+ private static readonly type = 'errors/javascript' as const ;
58+
5359 /**
5460 * JS Catcher version
5561 */
@@ -60,11 +66,6 @@ export default class Catcher {
6066 */
6167 public vue : VueIntegration | null = null ;
6268
63- /**
64- * Catcher Type
65- */
66- private readonly type : string = 'errors/javascript' ;
67-
6869 /**
6970 * User project's Integration Token
7071 */
@@ -91,13 +92,13 @@ export default class Catcher {
9192 * - Return `false` — the event will be dropped entirely.
9293 * - Any other value is invalid — the original event is sent as-is (a warning is logged).
9394 */
94- private readonly beforeSend : undefined | ( ( event : HawkJavaScriptEvent ) => HawkJavaScriptEvent | false | void ) ;
95+ private readonly beforeSend : undefined | ( ( event : HawkJavaScriptEvent < typeof Catcher . type > ) => HawkJavaScriptEvent < typeof Catcher . type > | false | void ) ;
9596
9697 /**
9798 * Transport for dialog between Catcher and Collector
9899 * (WebSocket decorator by default, or custom via settings.transport)
99100 */
100- private readonly transport : Transport ;
101+ private readonly transport : Transport < typeof Catcher . type > ;
101102
102103 /**
103104 * Module for parsing backtrace
@@ -410,7 +411,7 @@ export default class Catcher {
410411 *
411412 * @param errorFormatted - formatted error to send
412413 */
413- private sendErrorFormatted ( errorFormatted : CatcherMessage ) : void {
414+ private sendErrorFormatted ( errorFormatted : CatcherMessage < typeof Catcher . type > ) : void {
414415 this . transport . send ( errorFormatted )
415416 . catch ( ( sendingError ) => {
416417 log ( 'WebSocket sending error' , 'error' , sendingError ) ;
@@ -423,7 +424,7 @@ export default class Catcher {
423424 * @param error - error to format
424425 * @param context - any additional data passed by user
425426 */
426- private async prepareErrorFormatted ( error : Error | string , context ?: EventContext ) : Promise < CatcherMessage > {
427+ private async prepareErrorFormatted ( error : Error | string , context ?: EventContext ) : Promise < CatcherMessage < typeof Catcher . type > > {
427428 let payload : HawkJavaScriptEvent = {
428429 title : this . getTitle ( error ) ,
429430 type : this . getType ( error ) ,
@@ -479,7 +480,7 @@ export default class Catcher {
479480
480481 return {
481482 token : this . token ,
482- catcherType : this . type ,
483+ catcherType : Catcher . type ,
483484 payload,
484485 } ;
485486 }
@@ -516,7 +517,7 @@ export default class Catcher {
516517 * and reject() provided with text reason instead of Error()
517518 */
518519 if ( notAnError ) {
519- return null ;
520+ return undefined ;
520521 }
521522
522523 return ( error as Error ) . name ;
@@ -526,7 +527,7 @@ export default class Catcher {
526527 * Release version
527528 */
528529 private getRelease ( ) : HawkJavaScriptEvent [ 'release' ] {
529- return this . release !== undefined ? String ( this . release ) : null ;
530+ return this . release !== undefined ? String ( this . release ) : undefined ;
530531 }
531532
532533 /**
@@ -579,7 +580,7 @@ export default class Catcher {
579580 private getBreadcrumbsForEvent ( ) : HawkJavaScriptEvent [ 'breadcrumbs' ] {
580581 const breadcrumbs = this . breadcrumbManager ?. getBreadcrumbs ( ) ;
581582
582- return breadcrumbs && breadcrumbs . length > 0 ? breadcrumbs : null ;
583+ return breadcrumbs && breadcrumbs . length > 0 ? breadcrumbs : undefined ;
583584 }
584585
585586 /**
@@ -619,15 +620,15 @@ export default class Catcher {
619620 * and reject() provided with text reason instead of Error()
620621 */
621622 if ( notAnError ) {
622- return null ;
623+ return undefined ;
623624 }
624625
625626 try {
626627 return await this . stackParser . parse ( error as Error ) ;
627628 } catch ( e ) {
628629 log ( 'Can not parse stack:' , 'warn' , e ) ;
629630
630- return null ;
631+ return undefined ;
631632 }
632633 }
633634
@@ -693,7 +694,7 @@ export default class Catcher {
693694 * @param errorFormatted - Hawk event prepared for sending
694695 * @param integrationAddons - extra addons
695696 */
696- private appendIntegrationAddons ( errorFormatted : CatcherMessage , integrationAddons : JavaScriptCatcherIntegrations ) : void {
697- Object . assign ( errorFormatted . payload . addons , integrationAddons ) ;
697+ private appendIntegrationAddons ( errorFormatted : CatcherMessage < typeof Catcher . type > , integrationAddons : JavaScriptCatcherIntegrations ) : void {
698+ Object . assign ( errorFormatted . payload . addons ! , integrationAddons ) ;
698699 }
699700}
0 commit comments