@@ -27,6 +27,8 @@ import { isSuccessStatusCode } from "../utils/http_request_handler/http_util";
2727import { EventEmitter } from "../utils/event_emitter/event_emitter" ;
2828import { IdGenerator } from "../utils/id_generator" ;
2929import { areEventContextsEqual } from "./event_builder/user_event" ;
30+ import { EVENT_PROCESSOR_STOPPED , FAILED_TO_DISPATCH_EVENTS , FAILED_TO_DISPATCH_EVENTS_WITH_ARG } from "../exception_messages" ;
31+ import { sprintf } from "../utils/fns" ;
3032
3133export type EventWithId = {
3234 id : string ;
@@ -160,7 +162,7 @@ export class BatchEventProcessor extends BaseService implements EventProcessor {
160162 const dispatcher = closing && this . closingEventDispatcher ? this . closingEventDispatcher : this . eventDispatcher ;
161163 return dispatcher . dispatchEvent ( request ) . then ( ( res ) => {
162164 if ( res . statusCode && ! isSuccessStatusCode ( res . statusCode ) ) {
163- return Promise . reject ( new Error ( `Failed to dispatch events: ${ res . statusCode } ` ) ) ;
165+ return Promise . reject ( new Error ( sprintf ( FAILED_TO_DISPATCH_EVENTS_WITH_ARG , res . statusCode ) ) ) ;
164166 }
165167 return Promise . resolve ( res ) ;
166168 } ) ;
@@ -195,7 +197,7 @@ export class BatchEventProcessor extends BaseService implements EventProcessor {
195197 } ) . catch ( ( err ) => {
196198 // if the dispatch fails, the events will still be
197199 // in the store for future processing
198- this . logger ?. error ( 'Failed to dispatch events' , err ) ;
200+ this . logger ?. error ( FAILED_TO_DISPATCH_EVENTS , err ) ;
199201 } ) . finally ( ( ) => {
200202 this . runningTask . delete ( taskId ) ;
201203 ids . forEach ( ( id ) => this . dispatchingEventIds . delete ( id ) ) ;
@@ -253,7 +255,7 @@ export class BatchEventProcessor extends BaseService implements EventProcessor {
253255
254256 if ( this . isNew ( ) ) {
255257 // TOOD: replace message with imported constants
256- this . startPromise . reject ( new Error ( 'Event processor stopped before it could be started' ) ) ;
258+ this . startPromise . reject ( new Error ( EVENT_PROCESSOR_STOPPED ) ) ;
257259 }
258260
259261 this . state = ServiceState . Stopping ;
0 commit comments