handle errors in the app too

This commit is contained in:
Adam C. Baker
2015-01-26 18:07:38 -08:00
parent ead346816b
commit e1ad5cb1ae
2 changed files with 2 additions and 36 deletions
-35
View File
@@ -225,41 +225,6 @@ handleJsonObj reqBody handler = do
[("message", String "Expecting a JSON object")]
-- httpStatus :: H.TxError H.Postgres -> Status
-- httpStatus (H.ErroneousResult codeBS _ _ _) =
-- let code = cs codeBS in
-- case code of
-- '0' : '8' : _ -> status503 -- pg connection err
-- '0' : '9' : _ -> status500 -- triggered action exception
-- '0' : 'L' : _ -> status403 -- invalid grantor
-- '0' : 'P' : _ -> status403 -- invalid role specification
-- '2' : '5' : _ -> status500 -- invalid tx state
-- '2' : '8' : _ -> status403 -- invalid auth specification
-- '2' : 'D' : _ -> status500 -- invalid tx termination
-- '3' : '8' : _ -> status500 -- external routine exception
-- '3' : '9' : _ -> status500 -- external routine invocation
-- '3' : 'B' : _ -> status500 -- savepoint exception
-- '4' : '0' : _ -> status500 -- tx rollback
-- '5' : '3' : _ -> status503 -- insufficient resources
-- '5' : '4' : _ -> status413 -- too complex
-- '5' : '5' : _ -> status500 -- obj not on prereq state
-- '5' : '7' : _ -> status500 -- operator intervention
-- '5' : '8' : _ -> status500 -- system error
-- 'F' : '0' : _ -> status500 -- conf file error
-- 'H' : 'V' : _ -> status500 -- foreign data wrapper error
-- 'P' : '0' : _ -> status500 -- PL/pgSQL Error
-- 'X' : 'X' : _ -> status500 -- internal Error
-- "42P01" -> status404 -- undefined table
-- "42501" -> status404 -- insufficient privilege
-- _ -> status400
-- httpStatus (H.NoResult _) = status503 -- Received no response from the database.
-- -- (Maybe ByteString argument)
-- httpStatus (H.UnexpectedResult _) = status500 -- The database returned an unexpected result.
-- -- Indicates an improper statement or a schema mismatch.
-- -- (Text argument)
-- httpStatus H.NotInTransaction = status500
data TableOptions = TableOptions {
tblOptcolumns :: [Column]
, tblOptpkey :: [Text]
+2 -1
View File
@@ -4,6 +4,7 @@ import Paths_postgrest (version)
import App
import Middleware
import Error(errResponse)
import Control.Monad (unless)
import Control.Monad.IO.Class (liftIO)
@@ -56,7 +57,7 @@ main = do
body <- strictRequestBody req
resOrError <- liftIO $ H.session pool $ H.tx Nothing $
authenticated currRole anonRole (app body) req
either (undefined) respond resOrError
either (respond . errResponse) respond resOrError
where
describe = progDesc "create a REST API to an existing Postgres database"