From c2333c31caed4c52d8a071d42ec2b4c03edccbd9 Mon Sep 17 00:00:00 2001 From: Fabien Amarger Date: Mon, 25 Nov 2024 17:04:57 +0100 Subject: [PATCH] fix(route): Handle error on parameter `format` for route `/things` If parameter `format` is not in ['array', 'collection'] returns an appropriate error message. --- tdd/__init__.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tdd/__init__.py b/tdd/__init__.py index 66ec880..8343445 100644 --- a/tdd/__init__.py +++ b/tdd/__init__.py @@ -18,7 +18,7 @@ import time from threading import Thread import click -from flask import Flask, request, Response, stream_with_context +from flask import Flask, request, Response, stream_with_context, HTTPBadRequest import json from flask.cli import FlaskGroup import json_merge_patch @@ -109,9 +109,7 @@ def create_app(): for entry_point in entry_points(group="tdd_api.plugins.blueprints"): try: app.register_blueprint(entry_point.load()) - print( - f"Imported {entry_point.value} blueprint" - ) + print(f"Imported {entry_point.value} blueprint") except Exception as exc: print(f"ERROR ({entry_point.name}): {exc}") print( @@ -121,9 +119,7 @@ def create_app(): for entry_point in entry_points(group="tdd_api.plugins.transformers"): try: TD_TRANSFORMERS.append(entry_point.load()) - print( - f"Imported {entry_point.value} transformer" - ) + print(f"Imported {entry_point.value} transformer") except Exception as exc: print(f"ERROR ({entry_point.name}): {exc}") print( @@ -344,6 +340,9 @@ def generate(): f' etag="{get_collection_etag()}"' ) return response + raise HTTPBadRequest( + "'format' parameter is not recognized. Must be in 'array' or 'collection' if defined." + ) @app.route("/things/", methods=["GET"]) def describe_td(id):