From 0f09dd1d05eb3d4ac88004003b99ce67dea74bee Mon Sep 17 00:00:00 2001 From: patrick brisbin Date: Fri, 26 Feb 2021 14:46:44 -0500 Subject: [PATCH] In-line errLeft --- src/Yesod/Auth/OAuth2/Dispatch.hs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Yesod/Auth/OAuth2/Dispatch.hs b/src/Yesod/Auth/OAuth2/Dispatch.hs index 659588a..97b2018 100644 --- a/src/Yesod/Auth/OAuth2/Dispatch.hs +++ b/src/Yesod/Auth/OAuth2/Dispatch.hs @@ -86,18 +86,13 @@ dispatchCallback name oauth2 getToken getCreds = do code <- requireGetParam "code" manager <- authHttpManager oauth2' <- withCallbackAndState name oauth2 csrf - token <- - errLeft OAuth2ResultError $ getToken manager oauth2' $ ExchangeToken - code + token <- either (throwError . OAuth2ResultError) pure + =<< liftIO (getToken manager oauth2' $ ExchangeToken code) creds <- liftIO (getCreds manager token) `catch` (throwError . FetchCredsIOException) `catch` (throwError . FetchCredsYesodOAuth2Exception) setCredsRedirect creds - where - errLeft - :: (MonadIO m, MonadError e m) => (e' -> e) -> IO (Either e' a) -> m a - errLeft f = either (throwError . f) pure <=< liftIO withCallbackAndState :: (MonadError DispatchError m, MonadAuthHandler site m)