11import Socket from './modules/socket' ;
22import Sanitizer from './modules/sanitizer' ;
3- import log from './modules/logger ' ;
3+ import log from './utils/log ' ;
44import StackParser from './modules/stackParser' ;
55import type { CatcherMessage , HawkInitialSettings } from '@/types' ;
66import { VueIntegration } from './integrations/vue' ;
7- import { generateRandomId } from './utils' ;
7+ import { id } from './utils/id ' ;
88import type {
99 AffectedUser ,
1010 EventContext ,
@@ -15,6 +15,7 @@ import type {
1515import type { JavaScriptCatcherIntegrations } from './types/integrations' ;
1616import { EventRejectedError } from './errors' ;
1717import type { HawkJavaScriptEvent } from './types' ;
18+ import { isErrorProcessed , markErrorAsProcessed } from './utils/event' ;
1819
1920/**
2021 * Allow to use global VERSION, that will be overwritten by Webpack
@@ -153,7 +154,7 @@ export default class Catcher {
153154 if ( storedId ) {
154155 userId = storedId ;
155156 } else {
156- userId = generateRandomId ( ) ;
157+ userId = id ( ) ;
157158 localStorage . setItem ( LOCAL_STORAGE_KEY , userId ) ;
158159 }
159160
@@ -182,6 +183,18 @@ export default class Catcher {
182183 void this . formatAndSend ( message , undefined , context ) ;
183184 }
184185
186+ /**
187+ * Method for Frameworks SDK using own error handlers.
188+ * Allows to send errors to Hawk with additional Frameworks data (addons)
189+ *
190+ * @param error - error to send
191+ * @param [addons] - framework-specific data, can be undefined
192+ */
193+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
194+ public captureError ( error : Error | string , addons ?: JavaScriptCatcherIntegrations ) : void {
195+ void this . formatAndSend ( error , addons ) ;
196+ }
197+
185198 /**
186199 * Add error handing to the passed Vue app
187200 *
@@ -245,13 +258,24 @@ export default class Catcher {
245258 context ?: EventContext
246259 ) : Promise < void > {
247260 try {
261+ const isAlreadySentError = isErrorProcessed ( error ) ;
262+
263+ if ( isAlreadySentError ) {
264+ /**
265+ * @todo add debug build and log this case
266+ */
267+ return ;
268+ } else {
269+ markErrorAsProcessed ( error ) ;
270+ }
271+
248272 const errorFormatted = await this . prepareErrorFormatted ( error , context ) ;
249273
250274 /**
251275 * If this event caught by integration (Vue or other), it can pass extra addons
252276 */
253277 if ( integrationAddons ) {
254- this . appendIntegrationAddons ( errorFormatted , integrationAddons ) ;
278+ this . appendIntegrationAddons ( errorFormatted , Sanitizer . sanitize ( integrationAddons ) ) ;
255279 }
256280
257281 this . sendErrorFormatted ( errorFormatted ) ;
@@ -263,7 +287,7 @@ export default class Catcher {
263287 return ;
264288 }
265289
266- log ( 'Internal error ლ(´ڡ`ლ) ' , 'error ' , e ) ;
290+ log ( 'Unable to send error. Seems like it is Hawk internal bug. Please, report it here: https://github.com/codex-team/hawk.javascript/issues/new ' , 'warn ' , e ) ;
267291 }
268292 }
269293
0 commit comments