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
  • Loading branch information
FabioPinheiro authored and mineme0110 committed Apr 30, 2024
1 parent f3db2b6 commit a897d17
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 a897d17

Please sign in to comment.