Skip to content

Commit

Permalink
Improve naming around message exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
satabin committed Mar 29, 2024
1 parent 68ca822 commit 77cceae
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package com.commercetools.queue.aws.sqs
import cats.effect.Async
import cats.syntax.functor._
import cats.syntax.monadError._
import com.commercetools.queue.{MessageContext, Settlement}
import com.commercetools.queue.{Action, MessageContext}
import software.amazon.awssdk.services.sqs.SqsAsyncClient
import software.amazon.awssdk.services.sqs.model.{ChangeMessageVisibilityRequest, DeleteMessageRequest}

Expand All @@ -44,7 +44,7 @@ class SQSMessageContext[F[_], T](
client.deleteMessage(DeleteMessageRequest.builder().queueUrl(queueUrl).receiptHandle(receiptHandle).build())
}
}.void
.adaptError(makeSettlementException(_, queueName, messageId, Settlement.Ack))
.adaptError(makeMessageException(_, queueName, messageId, Action.Ack))

override def nack(): F[Unit] =
F.fromCompletableFuture {
Expand All @@ -58,7 +58,7 @@ class SQSMessageContext[F[_], T](
.build())
}
}.void
.adaptError(makeSettlementException(_, queueName, messageId, Settlement.Nack))
.adaptError(makeMessageException(_, queueName, messageId, Action.Nack))

override def extendLock(): F[Unit] =
F.fromCompletableFuture {
Expand All @@ -72,6 +72,6 @@ class SQSMessageContext[F[_], T](
.build())
}
}.void
.adaptError(makeSettlementException(_, queueName, messageId, Settlement.ExtendLock))
.adaptError(makeMessageException(_, queueName, messageId, Action.ExtendLock))

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.commercetools.queue.aws

import com.commercetools.queue.{CannotPullException, CannotPushException, CannotSettleException, QueueAlreadyExistException, QueueDoesNotExistException, QueueException, Settlement, UnknownQueueException}
import com.commercetools.queue.{Action, CannotPullException, CannotPushException, MessageException, QueueAlreadyExistException, QueueDoesNotExistException, QueueException, UnknownQueueException}
import software.amazon.awssdk.services.sqs.model.{QueueDoesNotExistException => AwsQueueDoesNotExistException, QueueNameExistsException}

package object sqs {
Expand All @@ -34,7 +34,7 @@ package object sqs {
def makePullQueueException(t: Throwable, queueName: String): QueueException =
new CannotPullException(queueName, makeQueueException(t, queueName))

def makeSettlementException(t: Throwable, queueName: String, msgId: String, action: Settlement): QueueException =
new CannotSettleException(msgId = msgId, action = action, inner = makeQueueException(t, queueName))
def makeMessageException(t: Throwable, queueName: String, msgId: String, action: Action): QueueException =
new MessageException(msgId = msgId, action = action, inner = makeQueueException(t, queueName))

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.commercetools.queue.azure

import com.azure.core.exception.{ResourceExistsException, ResourceNotFoundException}
import com.commercetools.queue.{CannotPullException, CannotPushException, CannotSettleException, QueueAlreadyExistException, QueueDoesNotExistException, QueueException, Settlement, UnknownQueueException}
import com.commercetools.queue.{Action, CannotPullException, CannotPushException, MessageException, QueueAlreadyExistException, QueueDoesNotExistException, QueueException, UnknownQueueException}

package object servicebus {

Expand All @@ -35,7 +35,7 @@ package object servicebus {
def makePullQueueException(t: Throwable, queueName: String): QueueException =
new CannotPullException(queueName, makeQueueException(t, queueName))

def makeSettlementException(t: Throwable, queueName: String, msgId: String, action: Settlement): QueueException =
new CannotSettleException(msgId = msgId, action = action, inner = makeQueueException(t, queueName))
def makeMessageException(t: Throwable, queueName: String, msgId: String, action: Action): QueueException =
new MessageException(msgId = msgId, action = action, inner = makeQueueException(t, queueName))

}
12 changes: 6 additions & 6 deletions core/src/main/scala/com/commercetools/queue/Settlement.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ package com.commercetools.queue

import cats.Show

sealed trait Settlement
sealed trait Action

object Settlement {
case object Ack extends Settlement
case object Nack extends Settlement
case object ExtendLock extends Settlement
object Action {
case object Ack extends Action
case object Nack extends Action
case object ExtendLock extends Action

implicit val show: Show[Settlement] = Show.show {
implicit val show: Show[Action] = Show.show {
case Ack => "ack"
case Nack => "nack"
case ExtendLock => "extend lock"
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/com/commercetools/queue/errors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ case class CannotPushException(name: String, inner: Throwable)
case class CannotPullException(name: String, inner: Throwable)
extends QueueException(show"Cannot pull messages from queue $name", inner)

case class CannotSettleException(msgId: String, action: Settlement, inner: Throwable)
case class MessageException(msgId: String, action: Action, inner: Throwable)
extends QueueException(show"Cannot $action message $msgId", inner)

case class UnknownQueueException(name: String, inner: Throwable)
Expand Down

0 comments on commit 77cceae

Please sign in to comment.