mirror of
https://github.com/nikita-volkov/hasql.git
synced 2024-11-23 02:35:33 +03:00
Explicit instance of MonadError for Tx
This commit is contained in:
parent
c02ba95858
commit
073acd578d
@ -192,8 +192,32 @@ session pool m =
|
||||
-- an unpredictable amount of times as well,
|
||||
-- which, chances are, is not what you want.
|
||||
newtype Tx c s r =
|
||||
Tx (EitherT (TxError c) (Bknd.Tx c) r)
|
||||
deriving (Functor, Applicative, Monad, MonadError (TxError c))
|
||||
Tx { unwrapTx :: EitherT (TxError c) (Bknd.Tx c) r }
|
||||
deriving (Functor, Applicative, Monad)
|
||||
|
||||
instance MonadError (TxError c) (Tx c s) where
|
||||
throwError =
|
||||
\case
|
||||
BackendTxError e ->
|
||||
Tx $ lift $ throwError e
|
||||
e ->
|
||||
Tx $ throwError e
|
||||
catchError m h =
|
||||
Tx $
|
||||
let
|
||||
m1 =
|
||||
let
|
||||
m2 =
|
||||
runEitherT $ unwrapTx $ m
|
||||
h2 =
|
||||
return . Left . BackendTxError
|
||||
in
|
||||
EitherT $ catchError m2 h2
|
||||
h1 =
|
||||
unwrapTx . h
|
||||
in
|
||||
catchError m1 h1
|
||||
|
||||
|
||||
data TxError c =
|
||||
-- |
|
||||
|
Loading…
Reference in New Issue
Block a user