Skip to content

Commit

Permalink
feat(connect): ATL-6599 Use ZIO Failures and Defects effectively + RF…
Browse files Browse the repository at this point in the history
…C-9457 in connect (#927)

Signed-off-by: Benjamin Voiturier <[email protected]>
  • Loading branch information
bvoiturier authored Mar 28, 2024
1 parent 9a38cc9 commit eb898e0
Show file tree
Hide file tree
Showing 35 changed files with 839 additions and 693 deletions.
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ lazy val D = new {
val zioTestSbt: ModuleID = "dev.zio" %% "zio-test-sbt" % V.zio % Test
val zioTestMagnolia: ModuleID = "dev.zio" %% "zio-test-magnolia" % V.zio % Test
val zioMock: ModuleID = "dev.zio" %% "zio-mock" % V.zioMock
val zioPrelude: ModuleID = "dev.zio" %% "zio-prelude" % V.zioPreludeVersion
val mockito: ModuleID = "org.scalatestplus" %% "mockito-4-11" % V.mockito % Test
val monocle: ModuleID = "dev.optics" %% "monocle-core" % V.monocle % Test
val monocleMacro: ModuleID = "dev.optics" %% "monocle-macro" % V.monocle % Test
Expand All @@ -176,11 +177,12 @@ lazy val D_Shared = new {
D.doobieHikari,
D.doobiePostgres,
D.zioCatsInterop,
D.zioPrelude,
D.jsonCanonicalization,
D.scodecBits,
D.circeCore,
D.circeGeneric,
D.circeParser,
D.circeParser
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ package io.iohk.atala.connect.core.model.error

sealed trait ConnectionRepositoryError extends Throwable

object ConnectionRepositoryError {
final case class UniqueConstraintViolation(message: String) extends ConnectionRepositoryError
}
object ConnectionRepositoryError {}
Original file line number Diff line number Diff line change
@@ -1,17 +1,55 @@
package io.iohk.atala.connect.core.model.error

import io.iohk.atala.connect.core.model.ConnectionRecord.ProtocolState
import io.iohk.atala.shared.models.{Failure, StatusCode}
import zio.NonEmptyChunk

import java.util.UUID

sealed trait ConnectionServiceError
sealed trait ConnectionServiceError(
val statusCode: StatusCode,
val userFacingMessage: String
) extends Failure

object ConnectionServiceError {
final case class RepositoryError(cause: Throwable) extends ConnectionServiceError
final case class RecordIdNotFound(recordId: UUID) extends ConnectionServiceError
final case class ThreadIdNotFound(thid: String) extends ConnectionServiceError
final case class InvitationParsingError(cause: Throwable) extends ConnectionServiceError
final case class UnexpectedError(msg: String) extends ConnectionServiceError
final case class InvalidFlowStateError(msg: String) extends ConnectionServiceError
final case class InvitationAlreadyReceived(msg: String) extends ConnectionServiceError
final case class InvitationExpired(msg: String) extends ConnectionServiceError

final case class UserInputValidationError(errors: NonEmptyChunk[String])
extends ConnectionServiceError(
StatusCode.BadRequest,
s"The provided input failed validation: errors=${errors.mkString("[", "], [", "]")}"
)
final case class InvitationParsingError(cause: String)
extends ConnectionServiceError(
StatusCode.BadRequest,
s"An error occurred while parsing the invitation content: cause=[$cause]"
)
final case class InvitationAlreadyReceived(invitationId: String)
extends ConnectionServiceError(
StatusCode.BadRequest,
s"The provided invitation has already been used: invitationId=$invitationId"
)
final case class RecordIdNotFound(recordId: UUID)
extends ConnectionServiceError(
StatusCode.NotFound,
s"There is no connection record matching the provided identifier: recordId=$recordId"
)
final case class ThreadIdNotFound(thid: String)
extends ConnectionServiceError(
StatusCode.NotFound,
s"There is no connection record matching the provided identifier: thid=$thid"
)
final case class ThreadIdMissingInReceivedMessage(msgId: String)
extends ConnectionServiceError(
StatusCode.BadRequest,
s"The received DIDComm message does not include a 'thid' field: messageId=$msgId"
)
final case class InvalidStateForOperation(state: ProtocolState)
extends ConnectionServiceError(
StatusCode.BadRequest,
s"The operation is not allowed for the current connection record state: $state=$state"
)
final case class InvitationExpired(invitationId: String)
extends ConnectionServiceError(
StatusCode.BadRequest,
s"The provided invitation has expired: invitationId=$invitationId"
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,71 @@ import io.iohk.atala.connect.core.model.ConnectionRecord
import io.iohk.atala.connect.core.model.ConnectionRecord.ProtocolState
import io.iohk.atala.mercury.protocol.connection.*
import io.iohk.atala.shared.models.WalletAccessContext
import zio.RIO
import zio.Task
import zio.UIO
import zio.URIO

import java.util.UUID

trait ConnectionRepository {
def createConnectionRecord(record: ConnectionRecord): RIO[WalletAccessContext, Int]

def getConnectionRecords: RIO[WalletAccessContext, Seq[ConnectionRecord]]
def create(
record: ConnectionRecord
): URIO[WalletAccessContext, Unit]

def findAll: URIO[WalletAccessContext, Seq[ConnectionRecord]]

def getConnectionRecordsByStates(
def findByStates(
ignoreWithZeroRetries: Boolean,
limit: Int,
states: ConnectionRecord.ProtocolState*
): RIO[WalletAccessContext, Seq[ConnectionRecord]]
): URIO[WalletAccessContext, Seq[ConnectionRecord]]

def getConnectionRecordsByStatesForAllWallets(
def findByStatesForAllWallets(
ignoreWithZeroRetries: Boolean,
limit: Int,
states: ConnectionRecord.ProtocolState*
): Task[Seq[ConnectionRecord]]
): UIO[Seq[ConnectionRecord]]

def findById(
recordId: UUID
): URIO[WalletAccessContext, Option[ConnectionRecord]]

def getConnectionRecord(recordId: UUID): RIO[WalletAccessContext, Option[ConnectionRecord]]
def getById(
recordId: UUID
): URIO[WalletAccessContext, ConnectionRecord]

def deleteConnectionRecord(recordId: UUID): RIO[WalletAccessContext, Int]
def deleteById(
recordId: UUID
): URIO[WalletAccessContext, Unit]

def getConnectionRecordByThreadId(thid: String): RIO[WalletAccessContext, Option[ConnectionRecord]]
def findByThreadId(
thid: String
): URIO[WalletAccessContext, Option[ConnectionRecord]]

def updateWithConnectionRequest(
recordId: UUID,
request: ConnectionRequest,
state: ProtocolState,
maxRetries: Int, // max numbre of retries -> set the metaRetries
): RIO[WalletAccessContext, Int]
maxRetries: Int,
): URIO[WalletAccessContext, Unit]

def updateWithConnectionResponse(
recordId: UUID,
response: ConnectionResponse,
state: ProtocolState,
maxRetries: Int, // max numbre of retries -> set the metaRetries
): RIO[WalletAccessContext, Int]
maxRetries: Int,
): URIO[WalletAccessContext, Unit]

def updateConnectionProtocolState(
def updateProtocolState(
recordId: UUID,
from: ProtocolState,
to: ProtocolState,
maxRetries: Int, // max numbre of retries -> set the metaRetries
): RIO[WalletAccessContext, Int]
maxRetries: Int,
): URIO[WalletAccessContext, Unit]

def updateAfterFail(
recordId: UUID,
failReason: Option[String],
): RIO[WalletAccessContext, Int]
): URIO[WalletAccessContext, Unit]

}
Loading

0 comments on commit eb898e0

Please sign in to comment.