<p dir="ltr">Hi.</p>
<p dir="ltr">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.</p>
<p dir="ltr">This way you won't need any evaluation tricks and will get all exceptions during that phase.</p>
<p dir="ltr">Cheers.<br>
</p>
<div class="gmail_quote">12 трав. 2015 05:11 "Alex" <<a href="mailto:alex323@gmail.com">alex323@gmail.com</a>> пише:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi:<br>
<br>
I am writing a small application which receives HTTP requests,<br>
translates them to JSON, and queues the requests using RabbitMQ.<br>
<br>
I am using exceptions to handle extreme cases, such as when a client's<br>
HTTP request lacks a critical header:<br>
<br>
lookupHeader :: RequestHeaders -> HeaderName -> Text<br>
lookupHeader hs h = decodeUtf8 $ fromMaybe notFound<br>
(lookup h hs)<br>
where<br>
notFound = throw $ MissingHeader $ decodeUtf8 $ original h<br>
<br>
The problem I am running in to is that the header isn't actually looked<br>
up until I call the AMQP library's publishMsg function. If I purposely<br>
do not supply a critical header, I get the following error printed to<br>
the screen:<br>
<br>
ConnectionClosedException "ConnectionClosedException \"UNEXPECTED_FRAME<br>
- expected content header for class 60, got non content header frame<br>
instead\""<br>
<br>
If I add the following line just above the publishMsg function (to<br>
force evaluation), my exception handler is called successfully:<br>
<br>
print $ encode req<br>
<br>
As a result, I suspect that this is due to the fact that the "throw<br>
MissingHeader" is getting captured by the AMQP library. What's the best<br>
way to deal with this situation?<br>
<br>
--<br>
Alex<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div>