Skip to content

Commit f2e3d9d

Browse files
committed
Consolidate duplicate exception handlers in subscriber loop
1 parent 7a4a4ea commit f2e3d9d

File tree

1 file changed

+9
-29
lines changed

1 file changed

+9
-29
lines changed

src/Foundatio.AWS/Messaging/SQSMessageBus.cs

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -513,10 +513,6 @@ await _sqsClient.Value.DeleteMessageAsync(new DeleteMessageRequest
513513
{
514514
_logger.LogWarning(ex, "Receipt handle invalid for message {MessageId}, message may have been deleted", sqsMessage.MessageId);
515515
}
516-
catch (AmazonServiceException ex)
517-
{
518-
_logger.LogError(ex, "AWS error processing message {MessageId}: {Message}", sqsMessage.MessageId, ex.Message);
519-
}
520516
catch (Exception ex)
521517
{
522518
_logger.LogError(ex, "Error processing message {MessageId}: {Message}", sqsMessage.MessageId, ex.Message);
@@ -532,36 +528,20 @@ await _sqsClient.Value.DeleteMessageAsync(new DeleteMessageRequest
532528
_logger.LogError(ex, "SQS queue no longer exists, stopping subscriber loop");
533529
break;
534530
}
535-
catch (AmazonServiceException ex)
536-
{
537-
_logger.LogError(ex, "AWS error in subscriber loop: {Message}", ex.Message);
538-
539-
if (!cancellationToken.IsCancellationRequested)
540-
{
541-
try
542-
{
543-
await _timeProvider.Delay(TimeSpan.FromSeconds(1), cancellationToken).AnyContext();
544-
}
545-
catch (OperationCanceledException)
546-
{
547-
// Ignored
548-
}
549-
}
550-
}
551531
catch (Exception ex)
552532
{
553533
_logger.LogError(ex, "Error in subscriber loop: {Message}", ex.Message);
554534

555-
if (!cancellationToken.IsCancellationRequested)
535+
if (cancellationToken.IsCancellationRequested)
536+
break;
537+
538+
try
556539
{
557-
try
558-
{
559-
await _timeProvider.Delay(TimeSpan.FromSeconds(1), cancellationToken).AnyContext();
560-
}
561-
catch (OperationCanceledException)
562-
{
563-
// Ignored
564-
}
540+
await _timeProvider.Delay(TimeSpan.FromSeconds(1), cancellationToken).AnyContext();
541+
}
542+
catch (OperationCanceledException)
543+
{
544+
break;
565545
}
566546
}
567547
}

0 commit comments

Comments
 (0)