Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could you please add catchFinishWith for Handlers? #203

Open
CristhianMotoche opened this issue Jun 19, 2018 · 2 comments
Open

Could you please add catchFinishWith for Handlers? #203

CristhianMotoche opened this issue Jun 19, 2018 · 2 comments

Comments

@CristhianMotoche
Copy link

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

@mightybyte
Copy link
Member

Sorry for the delay on this. I've been really busy. I agree that this seems like a useful thing. Unfortunately I don't have time to look at this right now. If you put together a pull request adding this, I'll be much more likely to get to it.

@CristhianMotoche
Copy link
Author

Hi @mightybyte . Sure thing! I'll be taking a look. Thanks for the answer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants