Skip to content

Commit

Permalink
Merge pull request #12 from Murloc6/fix_issue11
Browse files Browse the repository at this point in the history
fix(route): Handle error on parameter `format` for route `/things`
  • Loading branch information
wiresio authored Nov 29, 2024
2 parents df514bf + 51b7776 commit ec0545f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
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

0 comments on commit ec0545f

Please sign in to comment.