hyperledger-identus / hyperledger-identus/cloud-agent
500 instead of 409 when deactivating an already-deactivated or not-yet-published DID
- Dominant language
- Scala
- Stars
- 95
- Forks
- 34
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 14
Description
Split from #1883 (part 2).
## Description
`POST /did-registrar/dids/{didRef}/deactivations` returns `500` ("An unexpected error occurred when servicing the request") when it should return `409 Conflict` with a proper error body. Affected cases:
1. Deactivating an already-deactivated DID (`DIDAlreadyDeactivated`)
2. Deactivating a DID that is `CREATED` or `PUBLICATION_PENDING` (`DIDNotPublished`)
3. The `MultipleInflightUpdateNotAllowed` path (same mapping)
## Root cause
- The service layer correctly raises `UpdateManagedDIDError.DIDAlreadyDeactivated` / `DIDNotPublished` (`ManagedDIDServiceImpl.deactivateManagedDID`).
- The controller maps both to `ErrorResponse.conflict` (409) (`DIDRegistrarController`).
- But the `deactivateManagedDid` endpoint declares `errorOut(EndpointOutputs.basicFailuresAndForbiddenWith(FailureVariant.notFound))`, i.e. only 400/401/403/404/422/500. Unlike the sibling `updateManagedDid` endpoint, it has no `FailureVariant.conflict`.
- At runtime the 409 response fails tapir's `oneOf` encoding (no variant matches), the defect falls through to the generic handler in `CustomServerInterceptors`, and surfaces as 500.
Same class of bug as #1537 (fixed narrowly for the 401 variant on `/connections` in #1540).
## Fix
- Add `FailureVariant.conflict` to the `deactivations` endpoint's `errorOut`.
- Regenerate the OpenAPI spec.
- Add an HTTP-level test for the double-deactivation path (current tests only assert the service-layer error, so the missing variant was never caught).
## Environment
Observed on identus-cloud-agent 2.2.0, reproducible on current `main` (`85cb017f`).
Contributor guide
Research direction
Start with the deactivateManagedDid endpoint's errorOut declaration and compare it with the sibling updateManagedDid endpoint, then review DIDRegistrarController and the existing service-layer tests. Regenerate the OpenAPI spec and add an HTTP-level test for double deactivation; done means the affected cases return 409 Conflict with the proper error body instead of 500.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, scala
- Domain
- api, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100