Skip to content

Commit

Permalink
fix: incorrect body of the message results in problem report (#161)
Browse files Browse the repository at this point in the history
* fix:  incorrect body of the message results in problemreport

* fix:  incorrect body of the message results in problemreport

Signed-off-by: Shailesh Patil <53746241+mineme0110@users.noreply.github.com>
Signed-off-by: mineme0110 <shailesh.patil@iohk.io>
  • Loading branch information
mineme0110 committed May 1, 2024
1 parent d31ac6e commit 2a8eb90
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,35 @@ case class MediatorAgent(
}
// TODO Store context of the decrypt unwarping
// TODO SreceiveMessagetore context with MsgID and PIURI
agent <- ZIO.service[Agent]
ret <- {
maybeActionStorageError match
case Some(reply) => ActionUtils.packResponse(Some(plaintextMessage), reply)
case None => protocolHandler.execute(plaintextMessage)
}.tapError(ex => ZIO.logError(s"Error when execute Protocol: $ex"))
.catchSome { case MediatorDidError(error) =>
ZIO.logError(s"Error MediatorDidError: $error") *>
ActionUtils.packResponse(
Some(plaintextMessage),
Reply(
Problems
.malformedError(
to = plaintextMessage.from.map(_.asTO).toSet,
from = agent.id,
pthid = plaintextMessage.id,
piuri = plaintextMessage.`type`,
)
.toPlaintextMessage
)
)
}
} yield ret
}.catchAll {
case ex: MediatorError => ZIO.fail(ex)
case pr: ProblemReport => ActionUtils.packResponse(None, Reply(pr.toPlaintextMessage))
case ex: StorageCollection => ZIO.fail(ex)
case ex: StorageThrowable => ZIO.fail(ex)
case ex: DuplicateMessage => ZIO.fail(ex)
case ex: MediatorError => ZIO.fail(ex)
case pr: ProblemReport => ActionUtils.packResponse(None, Reply(pr.toPlaintextMessage))
case ex: StorageCollection => ZIO.fail(ex)
case ex: StorageThrowable => ZIO.fail(ex)
case ex: DuplicateMessage => ZIO.fail(ex)
}
} yield maybeSyncReplyMsg
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.iohk.atala.mediator.protocols

import fmgp.crypto.error.FailToParse
import fmgp.did.comm.{PIURI, PlaintextMessage, SignedMessage, EncryptedMessage}
import fmgp.did.comm.{EncryptedMessage, PIURI, PlaintextMessage, SignedMessage}
import fmgp.did.comm.protocol.basicmessage2.BasicMessage
import io.iohk.atala.mediator.{MediatorError, MediatorDidError, MediatorThrowable}
import io.iohk.atala.mediator.actions.{NoReply, ProtocolExecuter}
import io.iohk.atala.mediator.{MediatorDidError, MediatorError, MediatorThrowable, StorageError}
import io.iohk.atala.mediator.actions.{Action, NoReply, ProtocolExecuter}
import zio.{Console, ZIO}

object BasicMessageExecuter extends ProtocolExecuter[Any, MediatorError] {
Expand All @@ -16,7 +16,7 @@ object BasicMessageExecuter extends ProtocolExecuter[Any, MediatorError] {
): ZIO[R, MediatorError, Option[SignedMessage | EncryptedMessage]] =
program(plaintextMessage).debug *> ZIO.none

override def program[R1 <: Any](plaintextMessage: PlaintextMessage) = for {
override def program[R1 <: Any](plaintextMessage: PlaintextMessage): ZIO[R1, MediatorError, Action] = for {
job <- BasicMessage.fromPlaintextMessage(plaintextMessage) match
case Left(error) => ZIO.fail(MediatorDidError(FailToParse(error)))
case Right(bm) => Console.printLine(bm.toString).mapError(ex => MediatorThrowable(ex))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,21 @@ object Problems {
escalate_to = email,
)

def malformedError(
to: Set[TO],
from: FROM,
pthid: MsgID,
piuri: PIURI,
) = ProblemReport(
// id: MsgID = MsgID(),
to = to,
from = from,
pthid = pthid,
ack = None,
code = ProblemCode.ErroFail("msg", piuri.value),
comment = None,
args = None,
escalate_to = email,
)

}

0 comments on commit 2a8eb90

Please sign in to comment.