def wrapper_decorator(*args, **kwargs): response_headers = ResponseHeaders.merge( ResponseHeaders.allow_all_cors_headers(), ResponseHeaders.json_headers() ) try: return func(*args, **kwargs) except HttpException as ex: logger.exception('HTTP exception encountered.') data = ex.data() return Response.json( http_status=ex.http_code(), headers=response_headers, body=data ) except Exception as ex: logger.exception('Unexpected exception encountered.') error = InternalError(str(ex)) return Response.json( http_status=error.http_code(), headers=response_headers, body=error.data() )
def test_FUNC_json_WITH_test_dictionary_EXPECT_dictionary_returned() -> None: """ Test that the function can create an appropriate dictionary response from dictionary body. :return: No return. """ response = Response.json(200, body={'test_key': 'test_value'}) assert response == { 'body': '{"test_key": "test_value"}', 'isBase64Encoded': False, 'statusCode': 200 }