Skip to content

Commit

Permalink
Fix compilation even more
Browse files Browse the repository at this point in the history
  • Loading branch information
Artyom Kazak committed Apr 8, 2019
1 parent acad6d2 commit e0bed1e
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions services/spar/src/Spar/Scim.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ import Control.Monad.Except
import Data.String.Conversions (cs)
import Servant
import Servant.API.Generic
import Spar.App (Spar(..), Env)
import Spar.Error (SparError, sparToServantErr)
import Spar.App (Spar(..), Env(..))
import Spar.Error (SparError, sparToServantErrWithLogging)
import Spar.Scim.Types
import Spar.Scim.Auth
import Spar.Scim.User
Expand Down Expand Up @@ -97,28 +97,28 @@ apiScim = hoistScim (toServant (Scim.siteServer configuration))
-- FIXME: this doesn't catch impure exceptions (e.g. thrown with 'error').
-- Let's hope that SCIM clients can handle non-SCIM-formatted errors
-- properly. See <https://github.com/haskell-servant/servant/issues/1022>
-- for why it's hard to catch impure ex
-- for why it's hard to catch impure exceptions.
wrapScimErrors :: Spar a -> Spar a
wrapScimErrors = over (_Spar . mapped) $ \io ->
try @_ @SomeException io <&> \case
wrapScimErrors = over _Spar $ \act -> \env ->
try @_ @SomeException (act env) >>= \case
-- We caught an exception that's not a Spar exception. It is
-- wrapped into SCIM.serverError and rethrown.
Left someException ->
Left someException -> pure $
Left . SAML.CustomServant . Scim.scimToServantErr $
Scim.serverError (cs (displayException someException))
-- We caught a 'CustomServant' exception. It should be left as-is
-- because by now all SCIM errors have become 'CustomServant' errors
-- (thanks to 'toSpar') and we don't want to wrap them *again*.
Right (Left (SAML.CustomServant x)) ->
Right (Left (SAML.CustomServant x)) -> pure $
Left (SAML.CustomServant x)
-- We caught some other Spar exception. It should be wrapped into
-- SCIM.serverError and rethrown.
Right (Left sparError) ->
Left . SAML.CustomServant . Scim.scimToServantErr $
Scim.serverError (cs (errBody (sparToServantErr sparError)))
Right (Left sparError) -> do
err <- sparToServantErrWithLogging (sparCtxLogger env) sparError
pure $ Left . SAML.CustomServant . Scim.scimToServantErr $
Scim.serverError (cs (errBody err))
-- No exceptions! Good.
Right (Right x) ->
Right x
Right (Right x) -> pure $ Right x

-- This isomorphism unwraps the Spar stack (Spar . ReaderT . ExceptT) into a
-- newtype-less form that's easier to work with.
Expand Down

0 comments on commit e0bed1e

Please sign in to comment.