Roll back on db errors
This commit is contained in:
@@ -40,6 +40,7 @@ executable postgrest
|
|||||||
, http-types
|
, http-types
|
||||||
, interpolatedstring-perl6
|
, interpolatedstring-perl6
|
||||||
, jwt
|
, jwt
|
||||||
|
, mtl
|
||||||
, optparse-applicative >= 0.11 && < 0.13
|
, optparse-applicative >= 0.11 && < 0.13
|
||||||
, parsec
|
, parsec
|
||||||
, postgrest
|
, postgrest
|
||||||
@@ -92,6 +93,7 @@ library
|
|||||||
, http-types
|
, http-types
|
||||||
, interpolatedstring-perl6
|
, interpolatedstring-perl6
|
||||||
, jwt
|
, jwt
|
||||||
|
, mtl
|
||||||
, optparse-applicative
|
, optparse-applicative
|
||||||
, parsec
|
, parsec
|
||||||
, regex-tdfa
|
, regex-tdfa
|
||||||
@@ -173,6 +175,7 @@ Test-Suite spec
|
|||||||
, interpolatedstring-perl6
|
, interpolatedstring-perl6
|
||||||
, jwt
|
, jwt
|
||||||
, monad-control
|
, monad-control
|
||||||
|
, mtl
|
||||||
, optparse-applicative
|
, optparse-applicative
|
||||||
, parsec
|
, parsec
|
||||||
, process
|
, process
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import PostgREST.Middleware
|
|||||||
import PostgREST.Types (DbStructure)
|
import PostgREST.Types (DbStructure)
|
||||||
|
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
|
import Control.Monad.Error.Class (catchError, throwError)
|
||||||
import Data.Monoid ((<>))
|
import Data.Monoid ((<>))
|
||||||
import Data.String.Conversions (cs)
|
import Data.String.Conversions (cs)
|
||||||
import Data.Time.Clock.POSIX (getPOSIXTime)
|
import Data.Time.Clock.POSIX (getPOSIXTime)
|
||||||
@@ -95,5 +96,9 @@ postgrest conf dbStructure pool =
|
|||||||
|
|
||||||
let handleReq = runWithClaims conf time (app dbStructure conf body) req
|
let handleReq = runWithClaims conf time (app dbStructure conf body) req
|
||||||
resp <- either pgErrResponse id <$> P.use pool
|
resp <- either pgErrResponse id <$> P.use pool
|
||||||
(HT.run handleReq HT.ReadCommitted HT.Write)
|
(rollbackOnError $ HT.run handleReq HT.ReadCommitted HT.Write)
|
||||||
respond resp
|
respond resp
|
||||||
|
|
||||||
|
where
|
||||||
|
rollbackOnError :: H.Session a -> H.Session a
|
||||||
|
rollbackOnError = (`catchError` ((H.sql "rollback;" >>) . throwError))
|
||||||
|
|||||||
Reference in New Issue
Block a user