Skip to content

Commit 32f6399

Browse files
committed
chore: improve details field of the singular error response
1 parent 630e0a1 commit 32f6399

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2222
+ Note: data representations require Postgres 10 (Postgres 11 if using `IN` predicates); data representations are not implemented for RPC
2323
- #2647, Allow to verify the PostgREST version in SQL: `select distinct application_name from pg_stat_activity`. - @laurenceisla
2424
- #2856, Add the `--version` CLI option that prints the version information - @laurenceisla
25+
- #1655, Improve `details` field of the singular error response - @taimoorzaeem
2526

2627
### Fixed
2728

src/PostgREST/Error.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ instance JSON.ToJSON Error where
530530
toJSON (SingularityError n) = JSON.object [
531531
"code" .= ApiRequestErrorCode16,
532532
"message" .= ("JSON object requested, multiple (or no) rows returned" :: Text),
533-
"details" .= T.unwords ["Results contain", show n, "rows,", T.decodeUtf8 (MediaType.toMime MTSingularJSON), "requires 1 row"],
533+
"details" .= T.unwords ["The result contains", show n, "rows"],
534534
"hint" .= JSON.Null]
535535

536536
toJSON (PgErr err) = JSON.toJSON err

test/spec/Feature/Query/SingularSpec.hs

+16-16
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ spec =
6969
[("Prefer", "tx=commit"), singular]
7070
[json| { address: "zzz" } |]
7171
`shouldRespondWith`
72-
[json|{"details":"Results contain 4 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
72+
[json|{"details":"The result contains 4 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
7373
{ matchStatus = 406
7474
, matchHeaders = [ matchContentTypeSingular
7575
, "Preference-Applied" <:> "tx=commit" ]
@@ -85,7 +85,7 @@ spec =
8585
[("Prefer", "tx=commit"), ("Prefer", "return=representation"), singular]
8686
[json| { address: "zzz" } |]
8787
`shouldRespondWith`
88-
[json|{"details":"Results contain 4 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
88+
[json|{"details":"The result contains 4 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
8989
{ matchStatus = 406
9090
, matchHeaders = [ matchContentTypeSingular
9191
, "Preference-Applied" <:> "tx=commit" ]
@@ -100,7 +100,7 @@ spec =
100100
request methodPatch "/items?id=gt.0&id=lt.0"
101101
[singular] [json|{"id":1}|]
102102
`shouldRespondWith`
103-
[json|{"details":"Results contain 0 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
103+
[json|{"details":"The result contains 0 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
104104
{ matchStatus = 406
105105
, matchHeaders = [matchContentTypeSingular]
106106
}
@@ -109,7 +109,7 @@ spec =
109109
request methodPatch "/items?id=gt.0&id=lt.0"
110110
[("Prefer", "return=representation"), singular] [json|{"id":1}|]
111111
`shouldRespondWith`
112-
[json|{"details":"Results contain 0 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
112+
[json|{"details":"The result contains 0 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
113113
{ matchStatus = 406
114114
, matchHeaders = [matchContentTypeSingular]
115115
}
@@ -141,7 +141,7 @@ spec =
141141
[("Prefer", "tx=commit"), singular]
142142
[json| [ { id: 200, address: "xxx" }, { id: 201, address: "yyy" } ] |]
143143
`shouldRespondWith`
144-
[json|{"details":"Results contain 2 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
144+
[json|{"details":"The result contains 2 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
145145
{ matchStatus = 406
146146
, matchHeaders = [ matchContentTypeSingular
147147
, "Preference-Applied" <:> "tx=commit" ]
@@ -157,7 +157,7 @@ spec =
157157
[("Prefer", "tx=commit"), ("Prefer", "return=representation"), singular]
158158
[json| [ { id: 202, address: "xxx" }, { id: 203, address: "yyy" } ] |]
159159
`shouldRespondWith`
160-
[json|{"details":"Results contain 2 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
160+
[json|{"details":"The result contains 2 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
161161
{ matchStatus = 406
162162
, matchHeaders = [ matchContentTypeSingular
163163
, "Preference-Applied" <:> "tx=commit" ]
@@ -173,7 +173,7 @@ spec =
173173
[("Prefer", "tx=commit"), ("Prefer", "return=minimal"), singular]
174174
[json| [ { id: 204, address: "xxx" }, { id: 205, address: "yyy" } ] |]
175175
`shouldRespondWith`
176-
[json|{"details":"Results contain 2 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
176+
[json|{"details":"The result contains 2 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
177177
{ matchStatus = 406
178178
, matchHeaders = [ matchContentTypeSingular
179179
, "Preference-Applied" <:> "tx=commit" ]
@@ -189,7 +189,7 @@ spec =
189189
[singular]
190190
[json| [ ] |]
191191
`shouldRespondWith`
192-
[json|{"details":"Results contain 0 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
192+
[json|{"details":"The result contains 0 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
193193
{ matchStatus = 406
194194
, matchHeaders = [matchContentTypeSingular]
195195
}
@@ -199,7 +199,7 @@ spec =
199199
[("Prefer", "return=representation"), singular]
200200
[json| [ ] |]
201201
`shouldRespondWith`
202-
[json|{"details":"Results contain 0 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
202+
[json|{"details":"The result contains 0 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
203203
{ matchStatus = 406
204204
, matchHeaders = [matchContentTypeSingular]
205205
}
@@ -222,7 +222,7 @@ spec =
222222
[("Prefer", "tx=commit"), singular]
223223
""
224224
`shouldRespondWith`
225-
[json|{"details":"Results contain 5 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
225+
[json|{"details":"The result contains 5 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
226226
{ matchStatus = 406
227227
, matchHeaders = [ matchContentTypeSingular
228228
, "Preference-Applied" <:> "tx=commit" ]
@@ -240,7 +240,7 @@ spec =
240240
request methodDelete "/items?id=gt.5&id=lt.11"
241241
[("Prefer", "tx=commit"), ("Prefer", "return=representation"), singular] ""
242242
`shouldRespondWith`
243-
[json|{"details":"Results contain 5 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
243+
[json|{"details":"The result contains 5 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
244244
{ matchStatus = 406
245245
, matchHeaders = [ matchContentTypeSingular
246246
, "Preference-Applied" <:> "tx=commit" ]
@@ -257,7 +257,7 @@ spec =
257257
request methodDelete "/items?id=lt.0"
258258
[singular] ""
259259
`shouldRespondWith`
260-
[json|{"details":"Results contain 0 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
260+
[json|{"details":"The result contains 0 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
261261
{ matchStatus = 406
262262
, matchHeaders = [matchContentTypeSingular]
263263
}
@@ -266,7 +266,7 @@ spec =
266266
request methodDelete "/items?id=lt.0"
267267
[("Prefer", "return=representation"), singular] ""
268268
`shouldRespondWith`
269-
[json|{"details":"Results contain 0 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
269+
[json|{"details":"The result contains 0 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
270270
{ matchStatus = 406
271271
, matchHeaders = [matchContentTypeSingular]
272272
}
@@ -276,7 +276,7 @@ spec =
276276
request methodPost "/rpc/getproject"
277277
[singular] [json|{ "id": 9999999}|]
278278
`shouldRespondWith`
279-
[json|{"details":"Results contain 0 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
279+
[json|{"details":"The result contains 0 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
280280
{ matchStatus = 406
281281
, matchHeaders = [matchContentTypeSingular]
282282
}
@@ -299,7 +299,7 @@ spec =
299299
request methodPost "/rpc/getallprojects"
300300
[singular] "{}"
301301
`shouldRespondWith`
302-
[json|{"details":"Results contain 5 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
302+
[json|{"details":"The result contains 5 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
303303
{ matchStatus = 406
304304
, matchHeaders = [matchContentTypeSingular]
305305
}
@@ -314,7 +314,7 @@ spec =
314314
[("Prefer", "tx=commit"), singular]
315315
[json| {"id_l": 1, "id_h": 2, "name": "changed"} |]
316316
`shouldRespondWith`
317-
[json|{"details":"Results contain 2 rows, application/vnd.pgrst.object+json requires 1 row","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
317+
[json|{"details":"The result contains 2 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
318318
{ matchStatus = 406
319319
, matchHeaders = [ matchContentTypeSingular
320320
, "Preference-Applied" <:> "tx=commit" ]

0 commit comments

Comments
 (0)