
Hi.
I would suggest to separate data-extraction from request stage and
data-sending one. Create a data-structure that will represent a thing you
will want to send into RabbitMQ, and build it before you send anything.
Then catch exceptions in IO-based layer to handle exception case.
This way you won't need any evaluation tricks and will get all exceptions
during that phase.
Cheers.
12 трав. 2015 05:11 "Alex"
Hi:
I am writing a small application which receives HTTP requests, translates them to JSON, and queues the requests using RabbitMQ.
I am using exceptions to handle extreme cases, such as when a client's HTTP request lacks a critical header:
lookupHeader :: RequestHeaders -> HeaderName -> Text lookupHeader hs h = decodeUtf8 $ fromMaybe notFound (lookup h hs) where notFound = throw $ MissingHeader $ decodeUtf8 $ original h
The problem I am running in to is that the header isn't actually looked up until I call the AMQP library's publishMsg function. If I purposely do not supply a critical header, I get the following error printed to the screen:
ConnectionClosedException "ConnectionClosedException \"UNEXPECTED_FRAME - expected content header for class 60, got non content header frame instead\""
If I add the following line just above the publishMsg function (to force evaluation), my exception handler is called successfully:
print $ encode req
As a result, I suspect that this is due to the fact that the "throw MissingHeader" is getting captured by the AMQP library. What's the best way to deal with this situation?
-- Alex _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners