Skip to content

Commit c0d1560

Browse files
committed
issue2551069 - when unsupported type is found report type
When reporting an unsupported response type, error 406, report what type is seen by the code. Allows the user to better debug the query. E.G. look at the url and see if they mistyped it (e.g. by leaving a ? out of the url), or a mispelled accept header value or ....
1 parent e4c2928 commit c0d1560

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

roundup/rest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,8 +1985,8 @@ def dispatch(self, method, uri, input):
19851985
# error out before doing any work if we can't
19861986
# display acceptable output.
19871987
self.client.response_code = 406
1988-
output = ( "Requested content type is not available.\n"
1989-
"Acceptable types: %s"%(
1988+
output = ( "Requested content type '%s' is not available.\n"
1989+
"Acceptable types: %s"%(data_type,
19901990
", ".join(self.__accepted_content_type.keys())))
19911991

19921992
# Make output json end in a newline to

test/rest_common.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,8 @@ def testDispatch(self):
15441544

15451545

15461546
# TEST #8
1547-
# DELETE: delete issue 1
1547+
# DELETE: delete issue 1 also test return type by extension
1548+
# test bogus extension as well.
15481549
etag = calculate_etag(self.db.issue.getnode("1"),
15491550
self.db.config['WEB_SECRET_KEY'])
15501551
etagb = etag.strip ('"')
@@ -1569,11 +1570,20 @@ def testDispatch(self):
15691570
"/rest/data/issue/1.json",
15701571
form)
15711572
self.assertEqual(self.server.client.response_code, 200)
1572-
json_dict = json.loads(b2s(results))
15731573
print(results)
1574+
json_dict = json.loads(b2s(results))
15741575
status=json_dict['data']['status']
15751576
self.assertEqual(status, 'ok')
15761577

1578+
results = self.server.dispatch('DELETE',
1579+
"/rest/data/issue/1issue:=asdf.jon",
1580+
form)
1581+
self.assertEqual(self.server.client.response_code, 406)
1582+
print(results)
1583+
response="Requested content type 'jon' is not available.\n" \
1584+
"Acceptable types: */*, application/json, application/xml\n"
1585+
self.assertEqual(results, response)
1586+
15771587
# TEST #9
15781588
# GET: test that version can be set with accept:
15791589
# ... ; version=z

0 commit comments

Comments
 (0)