Skip to content

Commit

Permalink
Playground Tidying up a little error-handling code.
Browse files Browse the repository at this point in the history
  • Loading branch information
krisajenkins committed Jan 21, 2019
1 parent 0984f8f commit 90d7c52
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions plutus-playground/plutus-playground-server/app/Auth.hs
Expand Up @@ -21,7 +21,7 @@ module Auth

import Auth.Types (OAuthCode (OAuthCode), OAuthToken, Token (Token), TokenProvider (Github),
addUserAgent, oAuthTokenAccessToken)
import Control.Monad (guard, unless)
import Control.Monad (guard)
import Control.Monad.Except (MonadError)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Logger (MonadLogger, logDebugN, logErrorN)
Expand All @@ -47,7 +47,7 @@ import Network.HTTP.Client.Conduit (getUri)
import Network.HTTP.Client.TLS (tlsManagerSettings)
import Network.HTTP.Conduit (Request, newManager, parseRequest, responseBody, responseStatus,
setQueryString)
import Network.HTTP.Simple (addRequestHeader, getRequestQueryString)
import Network.HTTP.Simple (addRequestHeader)
import Network.HTTP.Types (hAccept, statusIsSuccessful)
import Servant ((:<|>) ((:<|>)), (:>), Get, Header, Headers, JSON, NoContent (NoContent),
QueryParam, ServantErr, ServerT, StdMethod (GET), ToHttpApiData, Verb,
Expand Down Expand Up @@ -196,7 +196,6 @@ extractGithubToken signer now cookieHeader =
case json of
String token -> pure $ Token token
_ -> Nothing

githubCallback ::
(MonadLogger m, MonadWeb m, MonadError ServantErr m, MonadNow m)
=> GithubEndpoints
Expand All @@ -211,11 +210,13 @@ githubCallback githubEndpoints config@Config {..} (Just code) = do
manager <- makeManager
let tokenRequest = makeTokenRequest githubEndpoints config code
response <- with500Err $ doRequest tokenRequest manager
unless
(statusIsSuccessful (responseStatus response))
(with500Err . pure . Left $ "Response: " <> Text.pack (show response))
token <-
with500Err $ pure $ first Text.pack $ eitherDecode $ responseBody response
with500Err $
pure $
first Text.pack $
if statusIsSuccessful (responseStatus response)
then eitherDecode $ responseBody response
else Left $ "Response: " <> show response
now <- getCurrentTime
let cookie = createSessionCookie _configJWTSignature token now
logDebugN "Sending cookie."
Expand Down

0 comments on commit 90d7c52

Please sign in to comment.