Skip to content

Could you please add catchFinishWith for Handlers? #203

@CristhianMotoche

Description

@CristhianMotoche

I want to integrate rollbar with my Snap web application. I want to log every user error or server error. I want to wrap all the routes using wrapSite.

In my Site.hs:

app :: SnapletInit App App
app = do
   ...
   wrapSite logIntoRollbar
   ...

In my case wrapSite expects a (Handler App App () -> Handler App App ()). Currently, my logIntoRollbar is something like this:

import Control.Exception.Lifted

logIntoRollbar :: Handler App App () -> Handler App App ()
logIntoRollbar handler = 
  bracket (handler >> getResponse) (checkAndSendRespToRollbar) finishWith

However, if during thehandler execution a badReq or a serverError occurs then any other code beyond that won't be executed, due to the finishEarly.

The catchFinishWith seems to solve this issue but it works in the Snap monad. It expects a Snap a and return a Snap (Either Response a).

I'd like to know if you add a catchFinishWithHandler :: Handler v k a -> Handler v k (Either Response a). I think it should be similar to bracketHandler which is a wrapper of bracketSnap

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions