fix: replace json parser error with generic msg (#3090)

This commit is contained in:
Andrei Dziahel
2023-12-07 18:04:51 -05:00
committed by GitHub
parent 41ea4e6db6
commit cbfff2804d
4 changed files with 8 additions and 5 deletions
+1
View File
@@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Fixed ### Fixed
- #3054, Fix not allowing special characters in JSON keys - @laurenceisla - #3054, Fix not allowing special characters in JSON keys - @laurenceisla
- #2344, Replace JSON parser error with a clearer generic message - @develop7
## [12.0.0] - 2023-12-01 ## [12.0.0] - 2023-12-01
+3 -1
View File
@@ -259,7 +259,9 @@ getPayload reqBody contentMediaType QueryParams{qsColumns} action PathInfo{pathI
else note "All object keys must match" . payloadAttributes reqBody else note "All object keys must match" . payloadAttributes reqBody
=<< if LBS.null reqBody && pathIsProc =<< if LBS.null reqBody && pathIsProc
then Right emptyObject then Right emptyObject
else first BS.pack $ JSON.eitherDecode reqBody else first BS.pack $
-- Drop parsing error message in favor of generic one (https://github.com/PostgREST/postgrest/issues/2344)
maybe (Left "Empty or invalid json") Right $ JSON.decode reqBody
(MTTextCSV, _) -> do (MTTextCSV, _) -> do
json <- csvToJson <$> first BS.pack (CSV.decodeByName reqBody) json <- csvToJson <$> first BS.pack (CSV.decodeByName reqBody)
note "All lines must have same number of fields" $ payloadAttributes (JSON.encode json) json note "All lines must have same number of fields" $ payloadAttributes (JSON.encode json) json
+2 -2
View File
@@ -287,7 +287,7 @@ spec actualPgVersion = do
it "fails with 400 and error" $ it "fails with 400 and error" $
post "/simple_pk" "}{ x = 2" post "/simple_pk" "}{ x = 2"
`shouldRespondWith` `shouldRespondWith`
[json|{"message":"Error in $: Failed reading: not a valid json value at '}{x=2'","code":"PGRST102","details":null,"hint":null}|] [json|{"message":"Empty or invalid json","code":"PGRST102","details":null,"hint":null}|]
{ matchStatus = 400 { matchStatus = 400
, matchHeaders = [matchContentTypeJson] , matchHeaders = [matchContentTypeJson]
} }
@@ -296,7 +296,7 @@ spec actualPgVersion = do
it "fails with 400 and error" $ it "fails with 400 and error" $
post "/simple_pk" "" post "/simple_pk" ""
`shouldRespondWith` `shouldRespondWith`
[json|{"message":"Error in $: not enough input","code":"PGRST102","details":null,"hint":null}|] [json|{"message":"Empty or invalid json","code":"PGRST102","details":null,"hint":null}|]
{ matchStatus = 400 { matchStatus = 400
, matchHeaders = [matchContentTypeJson] , matchHeaders = [matchContentTypeJson]
} }
+2 -2
View File
@@ -44,7 +44,7 @@ spec actualPgVersion = do
it "fails with 400 and error" $ it "fails with 400 and error" $
request methodPatch "/simple_pk" [] "}{ x = 2" request methodPatch "/simple_pk" [] "}{ x = 2"
`shouldRespondWith` `shouldRespondWith`
[json|{"message":"Error in $: Failed reading: not a valid json value at '}{x=2'","code":"PGRST102","details":null,"hint":null}|] [json|{"message":"Empty or invalid json","code":"PGRST102","details":null,"hint":null}|]
{ matchStatus = 400, { matchStatus = 400,
matchHeaders = [matchContentTypeJson] matchHeaders = [matchContentTypeJson]
} }
@@ -53,7 +53,7 @@ spec actualPgVersion = do
it "fails with 400 and error" $ it "fails with 400 and error" $
request methodPatch "/items" [] "" request methodPatch "/items" [] ""
`shouldRespondWith` `shouldRespondWith`
[json|{"message":"Error in $: not enough input","code":"PGRST102","details":null,"hint":null}|] [json|{"message":"Empty or invalid json","code":"PGRST102","details":null,"hint":null}|]
{ matchStatus = 400, { matchStatus = 400,
matchHeaders = [matchContentTypeJson] matchHeaders = [matchContentTypeJson]
} }