diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c053c04a..5f8bedbce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - #2651, Add the missing `get` path item for RPCs to the OpenAPI output - @laurenceisla + - #2648, Fix inaccurate error codes with new ones - @laurenceisla + + `PGRST204`: Column is not found + + `PGRST003`: Timed out when acquiring connection to db ## [10.1.2] - 2023-02-01 diff --git a/src/PostgREST/Error.hs b/src/PostgREST/Error.hs index aa59e02c5..b5ce4b306 100644 --- a/src/PostgREST/Error.hs +++ b/src/PostgREST/Error.hs @@ -212,7 +212,7 @@ instance JSON.ToJSON ApiRequestError where "details" .= JSON.Null, "hint" .= ("Try renaming the parameters or the function itself in the database so function overloading can be resolved" :: Text)] toJSON (ColumnNotFound relName colName) = JSON.object [ - "code" .= ApiRequestErrorCode18, + "code" .= SchemaCacheErrorCode04, "message" .= ("Column '" <> colName <> "' of relation '" <> relName <> "' does not exist" :: Text), "details" .= JSON.Null, "hint" .= JSON.Null] @@ -376,7 +376,7 @@ instance JSON.ToJSON SQL.UsageError where "hint" .= JSON.Null] toJSON (SQL.SessionUsageError e) = JSON.toJSON e -- SQL.Error toJSON SQL.AcquisitionTimeoutUsageError = JSON.object [ - "code" .= ConnectionErrorCode00, + "code" .= ConnectionErrorCode03, "message" .= ("Timed out acquiring connection from connection pool." :: Text), "details" .= JSON.Null, "hint" .= JSON.Null] @@ -575,6 +575,7 @@ data ErrorCode = ConnectionErrorCode00 | ConnectionErrorCode01 | ConnectionErrorCode02 + | ConnectionErrorCode03 -- API Request errors | ApiRequestErrorCode00 | ApiRequestErrorCode01 @@ -602,6 +603,7 @@ data ErrorCode | SchemaCacheErrorCode01 | SchemaCacheErrorCode02 | SchemaCacheErrorCode03 + | SchemaCacheErrorCode04 -- JWT authentication errors | JWTErrorCode00 | JWTErrorCode01 @@ -619,6 +621,7 @@ buildErrorCode code = "PGRST" <> case code of ConnectionErrorCode00 -> "000" ConnectionErrorCode01 -> "001" ConnectionErrorCode02 -> "002" + ConnectionErrorCode03 -> "003" ApiRequestErrorCode00 -> "100" ApiRequestErrorCode01 -> "101" @@ -646,6 +649,7 @@ buildErrorCode code = "PGRST" <> case code of SchemaCacheErrorCode01 -> "201" SchemaCacheErrorCode02 -> "202" SchemaCacheErrorCode03 -> "203" + SchemaCacheErrorCode04 -> "204" JWTErrorCode00 -> "300" JWTErrorCode01 -> "301" diff --git a/test/spec/Feature/Query/InsertSpec.hs b/test/spec/Feature/Query/InsertSpec.hs index 50053169d..db1def448 100644 --- a/test/spec/Feature/Query/InsertSpec.hs +++ b/test/spec/Feature/Query/InsertSpec.hs @@ -426,7 +426,7 @@ spec actualPgVersion = do {"id": 204, "body": "yyy"}, {"id": 205, "body": "zzz"}]|] `shouldRespondWith` - [json|{"code":"PGRST118","details":null,"hint":null,"message":"Column 'helicopter' of relation 'articles' does not exist"} |] + [json|{"code":"PGRST204","details":null,"hint":null,"message":"Column 'helicopter' of relation 'articles' does not exist"} |] { matchStatus = 400 , matchHeaders = [] } diff --git a/test/spec/Feature/Query/UpdateSpec.hs b/test/spec/Feature/Query/UpdateSpec.hs index ff0be3dcf..33061c91b 100644 --- a/test/spec/Feature/Query/UpdateSpec.hs +++ b/test/spec/Feature/Query/UpdateSpec.hs @@ -313,7 +313,7 @@ spec = do [("Prefer", "return=representation")] [json|{"body": "yyy"}|] `shouldRespondWith` - [json|{"code":"PGRST118","details":null,"hint":null,"message":"Column 'helicopter' of relation 'articles' does not exist"} |] + [json|{"code":"PGRST204","details":null,"hint":null,"message":"Column 'helicopter' of relation 'articles' does not exist"} |] { matchStatus = 400 , matchHeaders = [] }