Skip to content

Commit

Permalink
fix(route): Handle error on parameter format for route /things
Browse files Browse the repository at this point in the history
If parameter `format` is not in ['array', 'collection'] returns an
appropriate error message.
  • Loading branch information
Fabien Amarger committed Nov 25, 2024
1 parent df514bf commit c2333c3
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions tdd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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/<id>", methods=["GET"])
def describe_td(id):
Expand Down

0 comments on commit c2333c3

Please sign in to comment.