You can wrap your snap monad action in the exception functions from
Control.Exception.Lifted
<https://hackage.haskell.org/package/lifted-base-0.2.3.11/docs/Control-Exception-Lifted.html>.
You can also replace the toplevel exception handler via setErrorHandler
<https://github.com/snapframework/snap-server/blob/master/src/Snap/Internal/Http/Server/Config.hs#L503>
.

On Sat, May 20, 2017 at 10:33 PM, Henry Laxen <nadine.and.he...@gmail.com>
wrote:

> Dear Snappers,
>
> I've been using Snap for a few years now, and every few days I get an
> email like this:
>
> snip
> ...
> 177.192.105.60 - - [20/May/2017:21:25:42 -0400] "GET /static/favicon.ico
> HTTP/1.1" 200 3638 "http://maztravel.com/haskell/mySqlToCouchDB.html";
> "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like
> Gecko) Chrome/58.0.3029.110 Safari/537.36"
> ------------------------------------------------------------------------
> A web handler threw an exception. Details:
> sendfile: resource vanished (Connection reset by peer)
> [20/May/2017:16:28:56 -0400] Exception leaked to httpSession during phase
> 'user handler':
> During processing of request from 86.143.35.116:58136
> request:
> "GET /us/houses/reno/images/large/reno_n_bath1.jpg HTTP/1.1
> connection: Keep-Alive
> host: www.maztravel.com
> accept-encoding: gzip, deflate
> user-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0)
> like Gecko
> accept-language: en-GB
> accept: image/png, image/svg+xml, image/jxr, image/*;q=0.8, */*;q=0.5
> sn=\"www.maztravel.com\" c=86.143.35.116:58136 s=65.111.168.75:80 ctx=/
> clen=n/a"
> A web handler threw an exception. Details:
> TerminateSessionException sendfile: resource vanished (Connection reset by
> peer)
> [20/May/2017:18:06:32 -0400] Exception leaked to httpSession during phase
> 'sending-response':
> During processing of request from 172.56.20.36:42168
> request:
> "GET /maz/images/large/peso10a.jpg HTTP/1.1
> user-agent: com.google.GoogleMobile/27.0.0 iPhone/10.2 hw/iPhone8_1
> accept-encoding: gzip, deflate
> connection: keep-alive
> accept-language: en-us
> accept: */*
> host: www.maztravel.com
> sn=\"www.maztravel.com\" c=172.56.20.36:42168 s=65.111.168.75:80 ctx=/
> clen=n/a"
> A web handler threw an exception. Details:
> sendfile: resource vanished (Broken pipe)
> [20/May/2017:18:06:32 -0400] Exception leaked to httpSession during phase
> 'user handler':
> During processing of request from 172.56.20.36:42168
> request:
> "GET /maz/images/large/peso10a.jpg HTTP/1.1
> user-agent: com.google.GoogleMobile/27.0.0 iPhone/10.2 hw/iPhone8_1
> accept-encoding: gzip, deflate
> connection: keep-alive
> accept-language: en-us
> accept: */*
> host: www.maztravel.com
> sn=\"www.maztravel.com\" c=172.56.20.36:42168 s=65.111.168.75:80 ctx=/
> clen=n/a"
> A web handler threw an exception. Details:
> TerminateSessionException sendfile: resource vanished (Broken pipe)
>
>
> which has made me resort to a shell wrapper around my snap server (called
> nlh):
>
> while [ 1 ]; do
>     ./nlh -p 80
>     tail -20 log/access.log >access.txt
>     tail -20 log/error.log  >error.txt
>     cat access.txt divider.txt error.txt | mail -s "NLH crash" nadine.and.
> he...@pobox.com
> done
>
>
>
> So my question is how can I catch this exception in my code so
> that it doesn't escape to the top level.  The files above are
> static files being served by the following lines in the depths
> of the nlh code:
>
> import           Snap.Util.FileServe
> ...
>
>
> myServeFile  :: MonadSnap m => FilePath -> m ()
> myServeFile fp = do
>   setReferer -- just sets the Referer header
>   when isVideo $ extendTimeout (5 * 60)
> ----------------------------
>   serveFileAs mimeType fp -- from Snap.Util.FileServe
> ----------------------------
>   where
>     mimeType = fileType myMimeTypes (takeFileName fp)
>     isVideo = B8.take (length ("video" :: String)) mimeType ==  "video"
>
>
>
> Any pointers would be appreicated.
> Best wishes,
> Henry Laxen
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Snap Framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to snap_framework+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Gregory Collins <g...@gregorycollins.net>

-- 

--- 
You received this message because you are subscribed to the Google Groups "Snap 
Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to snap_framework+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to