@@ -409,6 +409,8 @@ describe("Consumer", () => {
409
409
} ) ;
410
410
411
411
it ( "waits before repolling when a credentials error occurs" , async ( ) => {
412
+ const loggerDebug = sandbox . stub ( logger , "debug" ) ;
413
+
412
414
const credentialsErr = {
413
415
name : "CredentialsError" ,
414
416
message : "Missing credentials in config" ,
@@ -424,9 +426,16 @@ describe("Consumer", () => {
424
426
sandbox . assert . calledTwice ( errorListener ) ;
425
427
sandbox . assert . calledWithMatch ( sqs . send . firstCall , mockReceiveMessage ) ;
426
428
sandbox . assert . calledWithMatch ( sqs . send . secondCall , mockReceiveMessage ) ;
429
+
430
+ sandbox . assert . calledWith ( loggerDebug , "authentication_error" , {
431
+ code : "CredentialsError" ,
432
+ detail : "There was an authentication error. Pausing before retrying." ,
433
+ } ) ;
427
434
} ) ;
428
435
429
436
it ( "waits before repolling when a 403 error occurs" , async ( ) => {
437
+ const loggerDebug = sandbox . stub ( logger , "debug" ) ;
438
+
430
439
const invalidSignatureErr = {
431
440
$metadata : {
432
441
httpStatusCode : 403 ,
@@ -444,9 +453,16 @@ describe("Consumer", () => {
444
453
sandbox . assert . calledTwice ( errorListener ) ;
445
454
sandbox . assert . calledWithMatch ( sqs . send . firstCall , mockReceiveMessage ) ;
446
455
sandbox . assert . calledWithMatch ( sqs . send . secondCall , mockReceiveMessage ) ;
456
+
457
+ sandbox . assert . calledWith ( loggerDebug , "authentication_error" , {
458
+ code : "Unknown" ,
459
+ detail : "There was an authentication error. Pausing before retrying." ,
460
+ } ) ;
447
461
} ) ;
448
462
449
463
it ( "waits before repolling when a UnknownEndpoint error occurs" , async ( ) => {
464
+ const loggerDebug = sandbox . stub ( logger , "debug" ) ;
465
+
450
466
const unknownEndpointErr = {
451
467
name : "UnknownEndpoint" ,
452
468
message :
@@ -464,9 +480,16 @@ describe("Consumer", () => {
464
480
sandbox . assert . calledTwice ( sqs . send ) ;
465
481
sandbox . assert . calledWithMatch ( sqs . send . firstCall , mockReceiveMessage ) ;
466
482
sandbox . assert . calledWithMatch ( sqs . send . secondCall , mockReceiveMessage ) ;
483
+
484
+ sandbox . assert . calledWith ( loggerDebug , "authentication_error" , {
485
+ code : "UnknownEndpoint" ,
486
+ detail : "There was an authentication error. Pausing before retrying." ,
487
+ } ) ;
467
488
} ) ;
468
489
469
490
it ( "waits before repolling when a NonExistentQueue error occurs" , async ( ) => {
491
+ const loggerDebug = sandbox . stub ( logger , "debug" ) ;
492
+
470
493
const nonExistentQueueErr = {
471
494
name : "AWS.SimpleQueueService.NonExistentQueue" ,
472
495
message : "The specified queue does not exist for this wsdl version." ,
@@ -483,9 +506,16 @@ describe("Consumer", () => {
483
506
sandbox . assert . calledTwice ( sqs . send ) ;
484
507
sandbox . assert . calledWithMatch ( sqs . send . firstCall , mockReceiveMessage ) ;
485
508
sandbox . assert . calledWithMatch ( sqs . send . secondCall , mockReceiveMessage ) ;
509
+
510
+ sandbox . assert . calledWith ( loggerDebug , "authentication_error" , {
511
+ code : "AWS.SimpleQueueService.NonExistentQueue" ,
512
+ detail : "There was an authentication error. Pausing before retrying." ,
513
+ } ) ;
486
514
} ) ;
487
515
488
516
it ( "waits before repolling when a CredentialsProviderError error occurs" , async ( ) => {
517
+ const loggerDebug = sandbox . stub ( logger , "debug" ) ;
518
+
489
519
const credentialsProviderErr = {
490
520
name : "CredentialsProviderError" ,
491
521
message : "Could not load credentials from any providers." ,
@@ -502,6 +532,141 @@ describe("Consumer", () => {
502
532
sandbox . assert . calledTwice ( sqs . send ) ;
503
533
sandbox . assert . calledWithMatch ( sqs . send . firstCall , mockReceiveMessage ) ;
504
534
sandbox . assert . calledWithMatch ( sqs . send . secondCall , mockReceiveMessage ) ;
535
+
536
+ sandbox . assert . calledWith ( loggerDebug , "authentication_error" , {
537
+ code : "CredentialsProviderError" ,
538
+ detail : "There was an authentication error. Pausing before retrying." ,
539
+ } ) ;
540
+ } ) ;
541
+
542
+ it ( "waits before repolling when a InvalidAddress error occurs" , async ( ) => {
543
+ const loggerDebug = sandbox . stub ( logger , "debug" ) ;
544
+
545
+ const credentialsProviderErr = {
546
+ name : "InvalidAddress" ,
547
+ message : "The address some-queue-url is not valid for this endpoint." ,
548
+ } ;
549
+ sqs . send . withArgs ( mockReceiveMessage ) . rejects ( credentialsProviderErr ) ;
550
+ const errorListener = sandbox . stub ( ) ;
551
+ consumer . on ( "error" , errorListener ) ;
552
+
553
+ consumer . start ( ) ;
554
+ await clock . tickAsync ( AUTHENTICATION_ERROR_TIMEOUT ) ;
555
+ consumer . stop ( ) ;
556
+
557
+ sandbox . assert . calledTwice ( errorListener ) ;
558
+ sandbox . assert . calledTwice ( sqs . send ) ;
559
+ sandbox . assert . calledWithMatch ( sqs . send . firstCall , mockReceiveMessage ) ;
560
+ sandbox . assert . calledWithMatch ( sqs . send . secondCall , mockReceiveMessage ) ;
561
+
562
+ sandbox . assert . calledWith ( loggerDebug , "authentication_error" , {
563
+ code : "InvalidAddress" ,
564
+ detail : "There was an authentication error. Pausing before retrying." ,
565
+ } ) ;
566
+ } ) ;
567
+
568
+ it ( "waits before repolling when a InvalidSecurity error occurs" , async ( ) => {
569
+ const loggerDebug = sandbox . stub ( logger , "debug" ) ;
570
+
571
+ const credentialsProviderErr = {
572
+ name : "InvalidSecurity" ,
573
+ message : "The queue is not is not HTTPS and SigV4." ,
574
+ } ;
575
+ sqs . send . withArgs ( mockReceiveMessage ) . rejects ( credentialsProviderErr ) ;
576
+ const errorListener = sandbox . stub ( ) ;
577
+ consumer . on ( "error" , errorListener ) ;
578
+
579
+ consumer . start ( ) ;
580
+ await clock . tickAsync ( AUTHENTICATION_ERROR_TIMEOUT ) ;
581
+ consumer . stop ( ) ;
582
+
583
+ sandbox . assert . calledTwice ( errorListener ) ;
584
+ sandbox . assert . calledTwice ( sqs . send ) ;
585
+ sandbox . assert . calledWithMatch ( sqs . send . firstCall , mockReceiveMessage ) ;
586
+ sandbox . assert . calledWithMatch ( sqs . send . secondCall , mockReceiveMessage ) ;
587
+
588
+ sandbox . assert . calledWith ( loggerDebug , "authentication_error" , {
589
+ code : "InvalidSecurity" ,
590
+ detail : "There was an authentication error. Pausing before retrying." ,
591
+ } ) ;
592
+ } ) ;
593
+
594
+ it ( "waits before repolling when a QueueDoesNotExist error occurs" , async ( ) => {
595
+ const loggerDebug = sandbox . stub ( logger , "debug" ) ;
596
+
597
+ const credentialsProviderErr = {
598
+ name : "QueueDoesNotExist" ,
599
+ message : "The queue does not exist." ,
600
+ } ;
601
+ sqs . send . withArgs ( mockReceiveMessage ) . rejects ( credentialsProviderErr ) ;
602
+ const errorListener = sandbox . stub ( ) ;
603
+ consumer . on ( "error" , errorListener ) ;
604
+
605
+ consumer . start ( ) ;
606
+ await clock . tickAsync ( AUTHENTICATION_ERROR_TIMEOUT ) ;
607
+ consumer . stop ( ) ;
608
+
609
+ sandbox . assert . calledTwice ( errorListener ) ;
610
+ sandbox . assert . calledTwice ( sqs . send ) ;
611
+ sandbox . assert . calledWithMatch ( sqs . send . firstCall , mockReceiveMessage ) ;
612
+ sandbox . assert . calledWithMatch ( sqs . send . secondCall , mockReceiveMessage ) ;
613
+
614
+ sandbox . assert . calledWith ( loggerDebug , "authentication_error" , {
615
+ code : "QueueDoesNotExist" ,
616
+ detail : "There was an authentication error. Pausing before retrying." ,
617
+ } ) ;
618
+ } ) ;
619
+
620
+ it ( "waits before repolling when a RequestThrottled error occurs" , async ( ) => {
621
+ const loggerDebug = sandbox . stub ( logger , "debug" ) ;
622
+
623
+ const credentialsProviderErr = {
624
+ name : "RequestThrottled" ,
625
+ message : "Requests have been throttled." ,
626
+ } ;
627
+ sqs . send . withArgs ( mockReceiveMessage ) . rejects ( credentialsProviderErr ) ;
628
+ const errorListener = sandbox . stub ( ) ;
629
+ consumer . on ( "error" , errorListener ) ;
630
+
631
+ consumer . start ( ) ;
632
+ await clock . tickAsync ( AUTHENTICATION_ERROR_TIMEOUT ) ;
633
+ consumer . stop ( ) ;
634
+
635
+ sandbox . assert . calledTwice ( errorListener ) ;
636
+ sandbox . assert . calledTwice ( sqs . send ) ;
637
+ sandbox . assert . calledWithMatch ( sqs . send . firstCall , mockReceiveMessage ) ;
638
+ sandbox . assert . calledWithMatch ( sqs . send . secondCall , mockReceiveMessage ) ;
639
+
640
+ sandbox . assert . calledWith ( loggerDebug , "authentication_error" , {
641
+ code : "RequestThrottled" ,
642
+ detail : "There was an authentication error. Pausing before retrying." ,
643
+ } ) ;
644
+ } ) ;
645
+
646
+ it ( "waits before repolling when a RequestThrottled error occurs" , async ( ) => {
647
+ const loggerDebug = sandbox . stub ( logger , "debug" ) ;
648
+
649
+ const credentialsProviderErr = {
650
+ name : "OverLimit" ,
651
+ message : "An over limit error." ,
652
+ } ;
653
+ sqs . send . withArgs ( mockReceiveMessage ) . rejects ( credentialsProviderErr ) ;
654
+ const errorListener = sandbox . stub ( ) ;
655
+ consumer . on ( "error" , errorListener ) ;
656
+
657
+ consumer . start ( ) ;
658
+ await clock . tickAsync ( AUTHENTICATION_ERROR_TIMEOUT ) ;
659
+ consumer . stop ( ) ;
660
+
661
+ sandbox . assert . calledTwice ( errorListener ) ;
662
+ sandbox . assert . calledTwice ( sqs . send ) ;
663
+ sandbox . assert . calledWithMatch ( sqs . send . firstCall , mockReceiveMessage ) ;
664
+ sandbox . assert . calledWithMatch ( sqs . send . secondCall , mockReceiveMessage ) ;
665
+
666
+ sandbox . assert . calledWith ( loggerDebug , "authentication_error" , {
667
+ code : "OverLimit" ,
668
+ detail : "There was an authentication error. Pausing before retrying." ,
669
+ } ) ;
505
670
} ) ;
506
671
507
672
it ( "waits before repolling when a polling timeout is set" , async ( ) => {
0 commit comments