Skip to content

Commit

Permalink
feat: Not send response errors to the caller (#50)
Browse files Browse the repository at this point in the history
Meditor should not send HTTP response with errors to the caller
For ATL-5200

Signed-off-by: Fabio Pinheiro <fabiomgpinheiro@gmail.com>

Signed-off-by: Shailesh Patil <shailesh.patil@iohk.io>
  • Loading branch information
FabioPinheiro authored and mineme0110 committed May 1, 2024
1 parent 4f416c2 commit 6cf0ac1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions mediator/src/main/scala/io/iohk/atala/mediator/Error.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6cf0ac1

Please sign in to comment.