I have a yesod application that uses http-client https://www.stackage.org/haddock/lts-9.0/http-client-0.5.7.0/Network-HTTP-Client.html#v:httpLbs . I am calling
resp <- httpLbs req man
inside the Handler (Response BSL.ByteString) monad.
I am getting this (in the application's log)
6/Aug/2017:15:14:17 +0200 [Error#yesod-core] HttpExceptionRequest Request { ...
(the next line of code never gets executed)
Instead, I want to catch the exception, and handle it in my code. How?
I'd recommend using the tryAny function from the safe-exceptions library. Roughly, this would look like:
eres <- tryAny $ httpLbs req man
case eres of
Left e -> handleException e
Right lbs -> handleBody lbs
Using safe-exceptions will help you avoid some corner cases you might otherwise run into with async exceptions and monad transformers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With