Skip to content

Handle some events before servant takes over #13

@ikervagyok

Description

@ikervagyok

Is it be possible, to pass in a function that resolves high-level application-specific effects into lower level effects like State x and especially into Error ServerError? This function would just be a chain of event-handlers.
This way you can use only high level effects in all servant handlers. You can resolve high level effects that could result in a Error ServerError before the servant machinery kicks in and all other effects still propagate outside.

interpretServer :: Env es -> Eff (Error ServerError : es) a -> Servant.Handler a
interpretServer env action = do
v <- liftIO $ do
es' <- cloneEnv env
unEff (runErrorNoCallStack action) es'
T.liftEither v

(I know its possible to handle effects in each effect handler manually, but that seems a lot more tedious than to have a clear boundary between the effects that could cause an Error ServerError and generic ones that can't/shouldn't.)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions