import * as Sentry from '@sentry/browser' ; import { Middleware } from 'driver/connect.js' ; import { IN_PRODUCTION_MODE , VERSION } from 'env' ; import { platform } from 'platforms' ; const PUBLIC_KEY = 'd22ec5c9cc874539a51c78388c12e3b0' ; const PROJECT_ID = '1406497' ; const MAX_REPORT_COUNT = 10 ; let countReportedError = 0 ; const errorSet = new Set < string > ( [ 'inThisSearch is null' , 'The quota has been exceeded.' , 'NetworkError when attempting to fetch resource.' , 'Failed to fetch' , ] ) ; const disabledIntegrations = [ 'TryCatch' , 'Breadcrumbs' , 'GlobalHandlers' , 'CaptureConsole' , ] ; const sentryOptions = { dsn : `https://${ PUBLIC_KEY }@sentry.io/${ PROJECT_ID }` , release : VERSION , environment : IN_PRODUCTION_MODE ? 'production' : 'development' , defaultIntegrations : IN_PRODUCTION_MODE ? undefined : false , integrations : integrations => integrations . filter ( ( { name } ) => ! disabledIntegrations . includes ( name ) ) , beforeSend ( event ) { const message = event . exception ?. values ?. [ 0 ] . value || event . message ; if ( message ) { if ( errorSet . has ( message ) ) return null ; errorSet . add ( message ) ; } if ( countReportedError < MAX_REPORT_COUNT ) { ++ countReportedError ; return event ; } return null ; } , beforeBreadcrumb ( breadcrumb , hint ) { if ( breadcrumb . category === 'ui.click' ) { const ariaLabel = hint ?. event ?. target ?. ariaLabel ; if ( ariaLabel ) { breadcrumb . message = ariaLabel ; } } return breadcrumb ; } , autoSessionTracking : false , } ; Sentry . init ( sentryOptions ) ; export const withErrorLog = function withErrorLog ( method , args ) { return [ async function ( ) { try { await method . apply ( null , arguments as any ) ; } catch ( error ) { raiseError ( error ) ; } } as any , args , ] ; } ; export function raiseError ( error , extra ? ) { if ( ! IN_PRODUCTION_MODE || platform . isEnterprise ( ) ) { console . error ( error ) ; console . error ( 'Extra:\n' , extra ) ; return ; } Sentry . withScope ( scope => { if ( extra ) { Object . keys ( extra ) . forEach ( key => { scope . setExtra ( key , extra [ key ] ) ; } ) ; } Sentry . captureException ( error ) ; } ) ; }