In-line errLeft

This commit is contained in:
patrick brisbin 2021-02-26 14:46:44 -05:00
parent 2d45a24e72
commit fee13fe23c
No known key found for this signature in database
GPG Key ID: 20299C6982D938FB

View File

@ -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)