[web-devel] Error catching in WAI and Warp

Michael Snoyman michael at snoyman.com
Fri Dec 16 06:16:44 CET 2011

On Fri, Dec 16, 2011 at 12:22 AM, Alexander Dorofeev <aka.spin at gmail.com> wrote:
> I has problem with error catching in WAI+Warp. Because, as I understand it,
> all response lives in Iteratee monad. And ofcourse all code is lazy.
> I found this gist: https://gist.github.com/1267589 - it helps to catch
> non-lazy errors (I just make WAI middleware). But if error occurs in lazy
> code:
>> responseLBS status200 [] undefined
> ... all dies. All errors goes to line 14 and Warp sends "200/OK" with empty
> response instead, for example '500/Internal Server Error'.
> How could handle all the errors?

I believe the only way to ensure this is to fully evaluate your
response before sending it to the server, and catching exceptions
during the evaluation. Also note that for a ResponseEnumerator, this
is by definition impossible: you'll be running IO code (which can
always fail) interleaved with your response body. This is the very
reason why, for most Yesod responses, I recommend avoiding
ResponseEnumerator, except for special circumstances like very large
output or times when it doesn't matter if the user gets a corrupted


More information about the web-devel mailing list