Skip to content

Commit

Permalink
feat(prism-agent): proper error for list did endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat Losoponkul committed Dec 2, 2022
1 parent 3d45d0b commit 09038ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.iohk.atala.agent.server.http.model

import akka.http.scaladsl.server.StandardRoute
import io.iohk.atala.agent.openapi.model.ErrorResponse
import io.iohk.atala.agent.walletapi.model.error.{CreateManagedDIDError, PublishManagedDIDError}
import io.iohk.atala.agent.walletapi.model.error.{CreateManagedDIDError, ListManagedDIDError, PublishManagedDIDError}
import io.iohk.atala.castor.core.model.did.w3c.DIDResolutionErrorRepr
import io.iohk.atala.castor.core.model.error.{DIDOperationError, DIDResolutionError}

Expand Down Expand Up @@ -44,6 +44,18 @@ trait OASErrorModelHelper {
}
}

given ToErrorResponse[ListManagedDIDError] with {
override def toErrorResponse(e: ListManagedDIDError): ErrorResponse = {
ErrorResponse(
`type` = "error-type",
title = "error-title",
status = 500,
detail = Some(e.toString),
instance = "error-instance"
)
}
}

given ToErrorResponse[PublishManagedDIDError] with {
override def toErrorResponse(e: PublishManagedDIDError): ErrorResponse = {
ErrorResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ class DIDRegistrarApiServiceImpl(service: ManagedDIDService)(using runtime: Runt
toEntityMarshallerListManagedDIDResponseInnerarray: ToEntityMarshaller[Seq[ListManagedDIDResponseInner]],
toEntityMarshallerErrorResponse: ToEntityMarshaller[ErrorResponse]
): Route = {
val result = service.listManagedDID.map(_.map(_.toOAS))
val result = service.listManagedDID
.map(_.map(_.toOAS))
.mapError(HttpServiceError.DomainError.apply)

onZioSuccess(result.either) {
case Left(error) => ??? // TODO: implement error handling
onZioSuccess(result.mapError(_.toOAS).either) {
case Left(error) => complete(error.status -> error)
case Right(result) => listManagedDid200(result)
}
}
Expand Down

0 comments on commit 09038ba

Please sign in to comment.