33 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44import Emittery from 'emittery' ;
55import { ProductConfigurationManager } from '@fxa/shared/cms' ;
6- import { Inject , Injectable } from '@nestjs/common' ;
6+ import { Inject , Injectable , Logger } from '@nestjs/common' ;
77import { CartManager , TaxChangeAllowedStatus } from '@fxa/payments/cart' ;
88import { PaymentsGleanManager } from '@fxa/payments/metrics' ;
99import { LocationStatus } from '@fxa/payments/eligibility' ;
@@ -13,12 +13,14 @@ import {
1313 PaymentsEmitterEvents ,
1414 SP3RolloutEvent ,
1515 SubscriptionEndedEvents ,
16+ type AuthEvents ,
1617} from './emitter.types' ;
1718import { AccountManager } from '@fxa/shared/account/account' ;
1819import { retrieveAdditionalMetricsData } from './util/retrieveAdditionalMetricsData' ;
1920import { getSubplatInterval } from '@fxa/payments/customer' ;
2021import * as Sentry from '@sentry/nestjs' ;
2122import { StatsD , StatsDService } from '@fxa/shared/metrics/statsd' ;
23+ import { EmitterServiceHandleAuthError } from './emitter.error' ;
2224
2325@Injectable ( )
2426export class PaymentsEmitterService {
@@ -29,7 +31,8 @@ export class PaymentsEmitterService {
2931 private paymentsGleanManager : PaymentsGleanManager ,
3032 private cartManager : CartManager ,
3133 private accountManager : AccountManager ,
32- @Inject ( StatsDService ) public statsd : StatsD
34+ @Inject ( StatsDService ) public statsd : StatsD ,
35+ private log : Logger
3336 ) {
3437 this . emitter = new Emittery < PaymentsEmitterEvents > ( ) ;
3538 this . emitter . on ( 'checkoutView' , this . handleCheckoutView . bind ( this ) ) ;
@@ -43,12 +46,22 @@ export class PaymentsEmitterService {
4346 ) ;
4447 this . emitter . on ( 'sp3Rollout' , this . handleSP3Rollout . bind ( this ) ) ;
4548 this . emitter . on ( 'locationView' , this . handleLocationView . bind ( this ) ) ;
49+ this . emitter . on ( 'auth' , this . handleAuthEvent . bind ( this ) ) ;
4650 }
4751
4852 getEmitter ( ) : Emittery < PaymentsEmitterEvents > {
4953 return this . emitter ;
5054 }
5155
56+ async handleAuthEvent ( eventData : AuthEvents ) {
57+ const { type, errorMessage } = eventData ;
58+ this . statsd . increment ( 'auth_event' , { type } ) ;
59+
60+ if ( errorMessage ) {
61+ this . log . error ( new EmitterServiceHandleAuthError ( errorMessage ) )
62+ }
63+ }
64+
5265 async handleCheckoutView ( eventData : CheckoutEvents ) {
5366 const additionalData = await retrieveAdditionalMetricsData (
5467 this . productConfigurationManager ,
0 commit comments