def _safe_handle(handler, args): try: start_time = time.time() rez = handler.handle(args) json_response = json_utils.to_json("response", rez) request_time = time.time() - start_time response = make_response(json_response) response.headers['Request-time'] = str(request_time) return response except BaseException as e: if not isinstance(e, BaseFMSException): LOG.exception(e) return json_utils.to_json("error", InnerServerError(e.message))
def test_json_serializable(self): class JsonClass(json_utils.JsonSerializable): pass obj = JsonClass() json_utils.to_json("k", obj)
def test_exception(self): exception = ValueError("test") expected = '{"resp": "test"}' self.assertEqual(json_utils.to_json("resp", exception), expected)