def json_response(response):
assert response.code == 200, 'bad http response'
return json.loads(response.body)
def custom_json_response(response):
response = json_response(response)
assert 'answer' in response, 'invalid custom json'
return response['answer']
The code looks straightforward but I wonder if there any chance to rewrite it to achieve the following:
- Replace
json_response
direct call with composition. - Code should not become a message from Sirius: everybody should still be able to understand it just without any efforts.
- It should be robust (composition type safety) yet easy extensible.
Any ideas?