Skip to content

Commit

Permalink
fix: get credential by said 404 response (#282)
Browse files Browse the repository at this point in the history
* fix: get cred by SAID should return 404 if missing instead of 500

* feat: raise 404 for cred not found after keripy update

* test: 404 get cred by said endpoint
  • Loading branch information
iFergal authored Sep 20, 2024
1 parent 7152dbb commit 62057ce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/keria/app/credentialing.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,16 +656,16 @@ def on_get(req, rep, said):
"""
agent = req.context.agent
accept = req.get_header("accept")
if accept == "application/json+cesr":
rep.content_type = "application/json+cesr"
data = CredentialResourceEnd.outputCred(agent.hby, agent.rgy, said)
else:
rep.content_type = "application/json"
creds = agent.rgy.reger.cloneCreds([coring.Saider(qb64=said)], db=agent.hby.db)
if not creds:
raise falcon.HTTPNotFound(description=f"credential for said {said} not found.")

data = json.dumps(creds[0]).encode("utf-8")
try:
if accept == "application/json+cesr":
rep.content_type = "application/json+cesr"
data = CredentialResourceEnd.outputCred(agent.hby, agent.rgy, said)
else:
rep.content_type = "application/json"
creds = agent.rgy.reger.cloneCreds([coring.Saider(qb64=said)], db=agent.hby.db)
data = json.dumps(creds[0]).encode("utf-8")
except kering.MissingEntryError:
raise falcon.HTTPNotFound(description=f"credential for said {said} not found.")

rep.status = falcon.HTTP_200
rep.data = bytes(data)
Expand Down
5 changes: 5 additions & 0 deletions tests/app/test_credentialing.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,11 @@ def test_credentialing_ends(helpers, seeder):
assert res.headers['content-type'] == "application/json"
assert res.json['sad']['d'] == saids[0]

res = client.simulate_get(f"/credentials/EDqDrGuzned0HOKFTLqd7m7O7WGE5zYIOHrlCq4EnWxy")
assert res.status_code == 404
assert res.json == {'description': f"credential for said EDqDrGuzned0HOKFTLqd7m7O7WGE5zYIOHrlCq4EnWxy not found.",
'title': '404 Not Found'}

headers = {"Accept": "application/json+cesr"}
res = client.simulate_get(f"/credentials/{saids[0]}", headers=headers)
assert res.status_code == 200
Expand Down

0 comments on commit 62057ce

Please sign in to comment.