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