import { EventProcessor , Hub , Integration } from '@sentry/types' ; import { getGlobalObject , isInstanceOf , logger } from '@sentry/utils' ; /** JSDoc */ export class Ember implements Integration { inheritDoc public static id : string = 'Ember' ; inheritDoc public name : string = Ember . id ; inheritDoc private readonly _Ember : any ; inheritDoc public constructor ( options = { } ) { this . _Ember = options . Ember || getGlobalObject < any > ( ) . Ember ; } inheritDoc public setupOnce ( _ , getCurrentHub ) { if ( ! this . _Ember ) { logger . error ( 'EmberIntegration is missing an Ember instance' ) ; return ; } const oldOnError = this . _Ember . onerror ; this . _Ember . onerror = ( error ) : void => { if ( getCurrentHub ( ) . getIntegration ( Ember ) ) { getCurrentHub ( ) . captureException ( error , { originalException : error } ) ; } if ( typeof oldOnError === 'function' ) { oldOnError . call ( this . _Ember , error ) ; } else if ( this . _Ember . testing ) { throw error ; } } ; this . _Ember . RSVP . on ( 'error' , ( reason ) : void => { if ( getCurrentHub ( ) . getIntegration ( Ember ) ) { getCurrentHub ( ) . withScope ( scope => { if ( isInstanceOf ( reason , Error ) ) { scope . setExtra ( 'context' , 'Unhandled Promise error detected' ) ; getCurrentHub ( ) . captureException ( reason , { originalException : reason as Error } ) ; } else { scope . setExtra ( 'reason' , reason ) ; getCurrentHub ( ) . captureMessage ( 'Unhandled Promise error detected' ) ; } } ) ; } } ) ; } }