diff --git a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/http/model/OASErrorModelHelper.scala b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/http/model/OASErrorModelHelper.scala index c5aa0ad98e..42a0076f5b 100644 --- a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/http/model/OASErrorModelHelper.scala +++ b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/http/model/OASErrorModelHelper.scala @@ -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} @@ -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( diff --git a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/http/service/DIDRegistrarApiServiceImpl.scala b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/http/service/DIDRegistrarApiServiceImpl.scala index 53775b49e2..d07c2f3e65 100644 --- a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/http/service/DIDRegistrarApiServiceImpl.scala +++ b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/http/service/DIDRegistrarApiServiceImpl.scala @@ -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) } }