def wrapper(self, request, suffix=''): """The wrapper function `json_handler` returns.""" if request.method != "POST": return JsonHandlerError(405, "Method must be POST").get_response(allow=["POST"]) try: request_json = json.loads(request.body) except ValueError: return JsonHandlerError(400, "Invalid JSON").get_response() try: response_json = json.dumps(func(self, request_json, suffix)) except JsonHandlerError as e: return e.get_response() return Response(response_json, content_type='application/json')
def wrapper(self, request, suffix=''): """The wrapper function `json_handler` returns.""" if request.method != "POST": return JsonHandlerError( 405, "Method must be POST").get_response(allow=["POST"]) try: request_json = json.loads(request.body) except ValueError: return JsonHandlerError(400, "Invalid JSON").get_response() try: response_json = json.dumps(func(self, request_json, suffix)) except JsonHandlerError as e: return e.get_response() return Response(response_json, content_type='application/json')
def wrapper(self, request, suffix=""): """The wrapper function `json_handler` returns.""" if request.method != "POST": return JsonHandlerError(405, "Method must be POST").get_response(allow=["POST"]) try: request_json = json.loads(request.body) except ValueError: return JsonHandlerError(400, "Invalid JSON").get_response() try: response = func(self, request_json, suffix) except JsonHandlerError as err: return err.get_response() if isinstance(response, Response): return response else: return Response(json.dumps(response), content_type="application/json")
def wrapper(self, request, suffix=''): """The wrapper function `json_handler` returns.""" request_json = json.loads(request.body) response_json = json.dumps(func(self, request_json, suffix)) return Response(response_json, content_type='application/json')
def wrapper(self, request): request_json = json.loads(request.body) response_json = json.dumps(fn(self, request_json)) return Response(response_json, content_type='application/json')