Skip to content

Commit

Permalink
fix(prism-agent): more descriptive error response for validateDID in …
Browse files Browse the repository at this point in the history
…issue flow (#783)

Signed-off-by: Pat Losoponkul <[email protected]>
  • Loading branch information
patlo-iog authored Nov 10, 2023
1 parent c87beb0 commit b99a737
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ private class DIDServiceImpl(didOpValidator: DIDOperationValidator, nodeClient:
.mapError(DIDOperationError.ValidationError.apply)
operationOutput <- ZIO
.fromFuture(_ => nodeClient.scheduleOperations(operationRequest))
.logError("Error scheduling Node operation")
.mapBoth(DIDOperationError.DLTProxyError.apply, _.outputs.toList)
.map {
case output :: Nil => Right(output)
Expand Down Expand Up @@ -81,6 +82,7 @@ private class DIDServiceImpl(didOpValidator: DIDOperationValidator, nodeClient:
for {
result <- ZIO
.fromFuture(_ => nodeClient.getOperationInfo(node_api.GetOperationInfoRequest(operationId.toProto)))
.logError("Error getting Node operation information")
.mapError(DIDOperationError.DLTProxyError.apply)
detail <- ZIO
.fromEither(result.toDomain)
Expand All @@ -98,6 +100,7 @@ private class DIDServiceImpl(didOpValidator: DIDOperationValidator, nodeClient:
}
result <- ZIO
.fromFuture(_ => nodeClient.getDidDocument(request))
.logError("Error resolving DID document from Node")
.mapError(DIDResolutionError.DLTProxyError.apply)
publishedDidData <- ZIO
.fromOption(result.document)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import io.iohk.atala.agent.server.ControllerHelper
import io.iohk.atala.agent.server.config.AppConfig
import io.iohk.atala.agent.walletapi.model.PublicationState
import io.iohk.atala.agent.walletapi.model.PublicationState.{Created, PublicationPending, Published}
import io.iohk.atala.agent.walletapi.model.error.GetManagedDIDError
import io.iohk.atala.agent.walletapi.service.ManagedDIDService
import io.iohk.atala.api.http.model.{CollectionStats, PaginationInput}
import io.iohk.atala.api.http.{ErrorResponse, RequestContext}
import io.iohk.atala.api.util.PaginationUtils
import io.iohk.atala.castor.core.model.did.PrismDID
import io.iohk.atala.castor.core.model.error.DIDResolutionError
import io.iohk.atala.castor.core.service.DIDService
import io.iohk.atala.connect.controller.ConnectionController
import io.iohk.atala.connect.core.model.error.ConnectionServiceError
Expand Down Expand Up @@ -191,20 +193,25 @@ class IssueControllerImpl(
ZIO.succeed(())
}
} yield result
result.mapError {
case e: ErrorResponse => e
case _ =>
ErrorResponse.internalServerError(detail = Some(s"Unexpected error while loading the PrismDID: $prismDID"))
}

mapIssueErrors(result)
}

private def mapIssueErrors[R, T](
result: ZIO[R, CredentialServiceError | ConnectionServiceError | ErrorResponse, T]
result: ZIO[
R,
CredentialServiceError | ConnectionServiceError | GetManagedDIDError | DIDResolutionError | ErrorResponse,
T
]
): ZIO[R, ErrorResponse, T] = {
result mapError {
case e: ErrorResponse => e
case connError: ConnectionServiceError => ConnectionController.toHttpError(connError)
case credError: CredentialServiceError => toHttpError(credError)
case resError: DIDResolutionError =>
ErrorResponse.internalServerError(detail = Some(s"Unable to resolve PrismDID. ${resError.toString()}"))
case getError: GetManagedDIDError =>
ErrorResponse.internalServerError(detail = Some(s"Unable to get PrismDID from storage. ${getError.toString()}"))
}
}

Expand Down

0 comments on commit b99a737

Please sign in to comment.