Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incorrect body of the message results in problem report #161

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)

}
Loading