Permalink
Browse files

Handling EMQ exceptions in SQS

  • Loading branch information...
1 parent 8ed4f0f commit 02c31bb741b47b846338b5fa656ca70a74b89963 @adamw committed Apr 1, 2012
@@ -1,22 +1,22 @@
package org.elasticmq
-class ElasticMQException(message: String, cause: Throwable)
+abstract class ElasticMQException(val code: String, message: String, cause: Throwable)
extends RuntimeException(message, cause)
class QueueDoesNotExistException(queueName: String)
- extends ElasticMQException("Queue does not exist: "+queueName, null)
+ extends ElasticMQException("QueueDoesNotExist", "Queue does not exist: "+queueName, null)
class QueueAlreadyExistsException(queueName: String)
- extends ElasticMQException("Queue alread exists: "+queueName, null)
+ extends ElasticMQException("QueueAlreadyExists", "Queue alread exists: "+queueName, null)
class MessageDoesNotExistException(queueName: String, messageId: MessageId)
- extends ElasticMQException("Message does not exist: "+messageId+" in queue: "+queueName, null)
+ extends ElasticMQException("MessageDoesNotExist", "Message does not exist: "+messageId+" in queue: "+queueName, null)
class NodeIsNotMasterException(masterAddress: Option[NodeAddress])
- extends ElasticMQException("Commands can be only executed on master server: " +
+ extends ElasticMQException("NodeIsNotMaster", "Commands can be only executed on master server: " +
masterAddress.map(_.address).getOrElse("unknown"), null)
class NodeIsNotActiveException(minimumNumberOfNodes: Int, currentNumberOfNodes: Int)
- extends ElasticMQException(
+ extends ElasticMQException("NodeIsNotActive",
"Node is not active. Currently %d nodes are active out of the minimum %d nodes required."
.format(minimumNumberOfNodes, currentNumberOfNodes), null)
@@ -3,10 +3,10 @@ package org.elasticmq.rest.sqs
import org.jboss.netty.handler.codec.http.HttpRequest
import org.elasticmq.rest.{StringResponse, RequestHandlerLogic}
-import org.elasticmq.Queue
import Constants._
import xml.Elem
+import org.elasticmq.{ElasticMQException, Queue}
trait RequestHandlerLogicModule { this: ClientModule =>
def logicWithQueue(body: (Queue, HttpRequest, Map[String, String]) => Elem): RequestHandlerLogic = {
@@ -58,8 +58,11 @@ trait RequestHandlerLogicModule { this: ClientModule =>
try {
super.handle(request, parameters)
} catch {
- case e: SQSException => StringResponse(e.toXml(EmptyRequestId).toString())
+ case e: SQSException => handleSQSException(e)
+ case e: ElasticMQException => handleSQSException(new SQSException(e.code, e.getMessage))
}
}
+
+ private def handleSQSException(e: SQSException) = StringResponse(e.toXml(EmptyRequestId).toString())
}
}
@@ -2,13 +2,16 @@ package org.elasticmq.rest.sqs
import Constants._
-class SQSException(message: String, httpStatusCode: Int = 400, errorType: String = "Sender") extends Exception {
+class SQSException(code: String,
+ message: String = "See the SQS docs.",
+ httpStatusCode: Int = 400,
+ errorType: String = "Sender") extends Exception {
def toXml(requestId: String) =
<ErrorResponse>
<Error>
<Type>{errorType}</Type>
- <Code>{message}</Code>
- <Message>See the SQS docs.</Message>
+ <Code>{code}</Code>
+ <Message>{message}</Message>
<Detail/>
</Error>
<RequestId>{requestId}</RequestId>

0 comments on commit 02c31bb

Please sign in to comment.