From 9f1ef0a2993feed7fd96b51652393afedd22fc2e Mon Sep 17 00:00:00 2001 From: Paul Warren Date: Thu, 26 Jan 2023 17:53:11 +0000 Subject: [PATCH 1/2] Ensure that status message is included on status line. --- flask_combo_jsonapi/decorators.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flask_combo_jsonapi/decorators.py b/flask_combo_jsonapi/decorators.py index 6e9b5fa..2954ada 100644 --- a/flask_combo_jsonapi/decorators.py +++ b/flask_combo_jsonapi/decorators.py @@ -73,8 +73,12 @@ def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except JsonApiException as e: + try: + status = int(e.status) + except: + status = e.status return make_response(jsonify(jsonapi_errors([e.to_dict()])), - e.status, + status, headers) except Exception as e: api_ex = format_http_exception(e) From ad22482c58028efd182eecc6d5f5d67265600619 Mon Sep 17 00:00:00 2001 From: Paul Warren Date: Thu, 3 Aug 2023 10:08:39 +0100 Subject: [PATCH 2/2] Restrict "except" to expected ValueError exception. --- flask_combo_jsonapi/decorators.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flask_combo_jsonapi/decorators.py b/flask_combo_jsonapi/decorators.py index 2954ada..ac81a81 100644 --- a/flask_combo_jsonapi/decorators.py +++ b/flask_combo_jsonapi/decorators.py @@ -73,9 +73,11 @@ def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except JsonApiException as e: + # If status is just a numeric code, convert it to an int so that + # flask expands it to a valid HTTP status line in the response. try: status = int(e.status) - except: + except ValueError: status = e.status return make_response(jsonify(jsonapi_errors([e.to_dict()])), status,