Skip to content

Commit

Permalink
fix: get cred by SAID should return 404 if missing instead of 500
Browse files Browse the repository at this point in the history
  • Loading branch information
iFergal committed Aug 7, 2024
1 parent f7e0890 commit 7e744fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/keria/app/credentialing.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,15 +656,16 @@ def on_get(req, rep, said):
"""
agent = req.context.agent
accept = req.get_header("accept")

if not agent.rgy.reger.creds.get(keys=(said,)):
raise falcon.HTTPNotFound(description=f"credential for said {said} not found.")

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")

rep.status = falcon.HTTP_200
Expand Down
4 changes: 4 additions & 0 deletions tests/app/test_credentialing.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ def test_credentialing_ends(helpers, seeder):
assert res.status_code == 200
assert res.headers['content-type'] == "application/json+cesr"

headers = {"Accept": "application/json+cesr"}
res = client.simulate_get(f"/credentials/doesNotExistSaid", headers=headers)
assert res.status_code == 404


def test_revoke_credential(helpers, seeder):
with helpers.openKeria() as (agency, agent, app, client):
Expand Down

0 comments on commit 7e744fe

Please sign in to comment.