Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(route): Handle error on parameter format for route /things #12

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions tdd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
JSONSchemaError,
IDNotFound,
WrongMimeType,
IncorrectlyDefinedParameter,
)
from tdd.td import (
clear_expired_td,
Expand Down Expand Up @@ -109,9 +110,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 +120,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 +341,9 @@ def generate():
f' etag="{get_collection_etag()}"'
)
return response
raise IncorrectlyDefinedParameter(
"'format' parameter is not recognized. Must be 'array' or 'collection' if defined."
)

@app.route("/things/<id>", methods=["GET"])
def describe_td(id):
Expand Down
17 changes: 5 additions & 12 deletions tdd/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
query,
)
from tdd.metadata import insert_metadata, delete_metadata
from tdd.errors import IDNotFound
from tdd.config import CONFIG


Expand Down Expand Up @@ -56,14 +55,11 @@ def json_ld_to_ntriples(ld_content):
input_data = json.dumps(ld_content) + "\n"
with resources.path("tdd.lib", "transform-to-nt.js") as transform_lib_path:
p = subprocess.Popen(
[
"node",
transform_lib_path
],
["node", transform_lib_path],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True
universal_newlines=True,
)
p.stdin.write(input_data)
p.stdin.flush()
Expand Down Expand Up @@ -111,14 +107,11 @@ def frame_nt_content(nt_content, frame):
input_data = json.dumps([ntriples, frame]) + "\n"
with resources.path("tdd.lib", "frame-jsonld.js") as frame_lib_path:
p = subprocess.Popen(
[
"node",
frame_lib_path
],
["node", frame_lib_path],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True
universal_newlines=True,
)
p.stdin.write(input_data)
p.stdin.flush()
Expand All @@ -136,6 +129,6 @@ def get_id_description(uri, content_type, ontology):
if not resp.text.strip() or not (
re.search(r"^[^\#]", resp.text, re.MULTILINE)
): # because some SPARQL endpoint may send "# Empty file" as response
#raise IDNotFound()
# raise IDNotFound()
abort(404)
return resp.text
4 changes: 4 additions & 0 deletions tdd/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,7 @@ def __init__(self, provided_mimetype):
f"Provided mimetype '{provided_mimetype}' is not supported. Only "
f"{', '.join(POSSIBLE_MIMETYPES)}, application/json are allowed"
)


class IncorrectlyDefinedParameter(AppException):
title = "Incorrectly defined parameter"
2 changes: 1 addition & 1 deletion tdd/sparql.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def query(
sparqlendpoint,
data={"update": querystring},
)

if resp.status_code not in status_codes:
raise FusekiError(resp)
return resp
Expand Down
Loading