From 6cf0ac1f9fbbc57778732157be0433f1b8d6604b Mon Sep 17 00:00:00 2001 From: Fabio Pinheiro Date: Thu, 13 Jul 2023 09:37:51 +0100 Subject: [PATCH] feat: Not send response errors to the caller (#50) Meditor should not send HTTP response with errors to the caller For ATL-5200 Signed-off-by: Fabio Pinheiro Signed-off-by: Shailesh Patil --- .../scala/io/iohk/atala/mediator/Error.scala | 4 +-- .../atala/mediator/app/MediatorAgent.scala | 28 +++++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/mediator/src/main/scala/io/iohk/atala/mediator/Error.scala b/mediator/src/main/scala/io/iohk/atala/mediator/Error.scala index efcc0cd6..36d17c33 100644 --- a/mediator/src/main/scala/io/iohk/atala/mediator/Error.scala +++ b/mediator/src/main/scala/io/iohk/atala/mediator/Error.scala @@ -14,7 +14,7 @@ object MediatorDidError { def apply(error: DidFail) = new MediatorDidError(error) } -final case class MediatorThrowable(val error: String) extends StorageError +final case class MediatorThrowable(val error: String) extends MediatorError object MediatorThrowable { def apply(throwable: Throwable) = new MediatorThrowable(throwable.getClass.getName() + ":" + throwable.getMessage) } @@ -47,4 +47,4 @@ object ProtocolError { } case class MissingProtocolError(piuri: PIURI) extends ProtocolError -case class FailToEncodeMessage(piuri: PIURI, error: String) extends ProtocolError +// case class FailToEncodeMessage(piuri: PIURI, error: String) extends ProtocolError diff --git a/mediator/src/main/scala/io/iohk/atala/mediator/app/MediatorAgent.scala b/mediator/src/main/scala/io/iohk/atala/mediator/app/MediatorAgent.scala index 7b515275..5280b08d 100644 --- a/mediator/src/main/scala/io/iohk/atala/mediator/app/MediatorAgent.scala +++ b/mediator/src/main/scala/io/iohk/atala/mediator/app/MediatorAgent.scala @@ -241,14 +241,30 @@ object MediatorAgent { for { agent <- ZIO.service[MediatorAgent] data <- req.body.asString - maybeSyncReplyMsg <- agent + ret <- agent .receiveMessage(data, None) - .mapError(fail => MediatorException(fail)) - ret = maybeSyncReplyMsg match - case None => Response.ok - case Some(value) => Response.json(value.toJson) + .map { + case None => Response.ok + case Some(value) => Response.json(value.toJson) + } + .catchAll { + case MediatorDidError(error) => + ZIO.logError(s"Error MediatorDidError: $error") *> + ZIO.succeed(Response.status(Status.BadRequest)) + case MediatorThrowable(error) => + ZIO.logError(s"Error MediatorThrowable: $error") *> + ZIO.succeed(Response.status(Status.BadRequest)) + case StorageCollection(error) => + ZIO.logError(s"Error StorageCollection: $error") *> + ZIO.succeed(Response.status(Status.BadRequest)) + case StorageThrowable(error) => + ZIO.logError(s"Error StorageThrowable: $error") *> + ZIO.succeed(Response.status(Status.BadRequest)) + case MissingProtocolError(piuri) => + ZIO.logError(s"MissingProtocolError ('$piuri')") *> + ZIO.succeed(Response.status(Status.BadRequest)) // TODO + } } yield ret - // TODO [return_route extension](https://github.com/decentralized-identity/didcomm-messaging/blob/main/extensions/return_route/main.md) case req @ Method.POST -> !! => ZIO