Skip to content

Commit

Permalink
fix: use existing error codes
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bluhm <[email protected]>
  • Loading branch information
dbluhm committed Aug 2, 2023
1 parent e8c8915 commit ca3eb3e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
16 changes: 13 additions & 3 deletions aries_cloudagent/protocols/didexchange/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ async def accept_complete(

return conn_rec

async def abandon_exchange(
async def reject(
self,
conn_rec: ConnRecord,
*,
Expand All @@ -866,10 +866,20 @@ async def abandon_exchange(
async with self.profile.session() as session:
await conn_rec.abandon(session, reason=reason)

state_to_reject_code = {
"invitation-received": ProblemReportReason.INVITATION_NOT_ACCEPTED,
"request-received": ProblemReportReason.REQUEST_NOT_ACCEPTED,
}
code = state_to_reject_code.get(conn_rec.rfc23_state)
if not code:
raise DIDXManagerError(
f"Cannot reject connection in state: {conn_rec.state}"
)

report = DIDXProblemReport(
description={
"code": ProblemReportReason.ABANDONED.value,
"en": reason or "Connection abandoned",
"code": code.value,
"en": reason or "DID exchange rejected",
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class ProblemReportReason(Enum):
RESPONSE_NOT_ACCEPTED = "response_not_accepted"
RESPONSE_PROCESSING_ERROR = "response_processing_error"
COMPLETE_NOT_ACCEPTED = "complete_not_accepted"
ABANDONED = "abandoned"


class DIDXProblemReport(ProblemReport):
Expand Down
2 changes: 1 addition & 1 deletion aries_cloudagent/protocols/didexchange/v1_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ async def didx_reject(request: web.BaseRequest):
try:
async with profile.session() as session:
conn_rec = await ConnRecord.retrieve_by_id(session, connection_id)
report = await didx_mgr.abandon_exchange(conn_rec=conn_rec)
report = await didx_mgr.reject(conn_rec=conn_rec)
except StorageNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err
except (StorageError, WalletError, DIDXManagerError, BaseModelError) as err:
Expand Down

0 comments on commit ca3eb3e

Please sign in to comment.