From abb0ab557a4af097b4f533fc7524ade387d89a4c Mon Sep 17 00:00:00 2001 From: patrick brisbin Date: Fri, 26 Feb 2021 14:46:07 -0500 Subject: [PATCH] In-line tryFetchCreds --- src/Yesod/Auth/OAuth2/Dispatch.hs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Yesod/Auth/OAuth2/Dispatch.hs b/src/Yesod/Auth/OAuth2/Dispatch.hs index 49c32c6..659588a 100644 --- a/src/Yesod/Auth/OAuth2/Dispatch.hs +++ b/src/Yesod/Auth/OAuth2/Dispatch.hs @@ -89,19 +89,16 @@ dispatchCallback name oauth2 getToken getCreds = do token <- errLeft OAuth2ResultError $ getToken manager oauth2' $ ExchangeToken code - creds <- errLeft id $ tryFetchCreds $ getCreds manager token + 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 -tryFetchCreds :: IO a -> IO (Either DispatchError a) -tryFetchCreds f = - (Right <$> f) - `catch` (pure . Left . FetchCredsIOException) - `catch` (pure . Left . FetchCredsYesodOAuth2Exception) - withCallbackAndState :: (MonadError DispatchError m, MonadAuthHandler site m) => Text