Skip to content

Commit

Permalink
ATL-6835: Present Error Handling
Browse files Browse the repository at this point in the history
Signed-off-by: Bassam Riman <bassam.riman@iohk.io>
  • Loading branch information
CryptoKnightIOG committed Jun 10, 2024
1 parent ede7b77 commit 1fd43a8
Show file tree
Hide file tree
Showing 12 changed files with 469 additions and 521 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ trait PresentProofController {
object PresentProofController {
def toHttpError(error: PresentationError): ErrorResponse =
error match
case PresentationError.RepositoryError(cause) =>
ErrorResponse.internalServerError(title = "RepositoryError", detail = Some(cause.toString))
case PresentationError.RecordIdNotFound(recordId) =>
ErrorResponse.notFound(detail = Some(s"Record Id not found: $recordId"))
case PresentationError.ThreadIdNotFound(thid) =>
Expand Down Expand Up @@ -66,8 +64,6 @@ object PresentProofController {
ErrorResponse.internalServerError(detail = Some("Issued credential not found"))
case PresentationError.PresentationDecodingError(_) =>
ErrorResponse.internalServerError(detail = Some("Presentation decoding error"))
case PresentationError.PresentationNotFoundError(_) =>
ErrorResponse.notFound(detail = Some("Presentation no found"))
case PresentationError.HolderBindingError(msg) =>
ErrorResponse.internalServerError(detail = Some(s"Holder binding error: $msg"))
case PresentationError.MissingCredential =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class PresentProofControllerImpl(
val result = for {
records <- thid match
case None => presentationService.getPresentationRecords(ignoreWithZeroRetries = false)
case Some(thid) => presentationService.getPresentationRecordByThreadId(DidCommID(thid)).map(_.toSeq)
case Some(thid) => presentationService.findPresentationRecordByThreadId(DidCommID(thid)).map(_.toSeq)
} yield PresentationStatusPage(
records.map(PresentationStatus.fromDomain)
)
Expand All @@ -121,7 +121,7 @@ class PresentProofControllerImpl(
)(implicit rc: RequestContext): ZIO[WalletAccessContext, ErrorResponse, PresentationStatus] = {
val result: ZIO[WalletAccessContext, ErrorResponse | PresentationError, PresentationStatus] = for {
presentationId <- toDidCommID(id.toString)
maybeRecord <- presentationService.getPresentationRecord(presentationId)
maybeRecord <- presentationService.findPresentationRecord(presentationId)
record <- ZIO
.fromOption(maybeRecord)
.mapError(_ => ErrorResponse.notFound(detail = Some(s"Presentation record not found: $id")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import org.hyperledger.identus.pollux.core.model.DidCommID
sealed trait PresentationError

object PresentationError {
final case class RepositoryError(cause: Throwable) extends PresentationError
final case class RecordIdNotFound(recordId: DidCommID) extends PresentationError
final case class ThreadIdNotFound(thid: DidCommID) extends PresentationError
final case class InvalidFlowStateError(msg: String) extends PresentationError
final case class UnexpectedError(msg: String) extends PresentationError
final case class IssuedCredentialNotFoundError(cause: String) extends PresentationError
final case class NotMatchingPresentationCredentialFormat(cause: Throwable) extends PresentationError
final case class PresentationDecodingError(cause: String) extends PresentationError
final case class PresentationNotFoundError(cause: Throwable) extends PresentationError
final case class HolderBindingError(msg: String) extends PresentationError
object MissingCredential extends PresentationError
object MissingCredentialFormat extends PresentationError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,66 +7,72 @@ import org.hyperledger.identus.shared.models.WalletAccessContext
import zio.*

trait PresentationRepository {
def createPresentationRecord(record: PresentationRecord): RIO[WalletAccessContext, Int]
def getPresentationRecords(ignoreWithZeroRetries: Boolean): RIO[WalletAccessContext, Seq[PresentationRecord]]
def getPresentationRecord(recordId: DidCommID): RIO[WalletAccessContext, Option[PresentationRecord]]
def createPresentationRecord(record: PresentationRecord): URIO[WalletAccessContext, Unit]

def getPresentationRecords(ignoreWithZeroRetries: Boolean): URIO[WalletAccessContext, Seq[PresentationRecord]]

def findPresentationRecord(recordId: DidCommID): URIO[WalletAccessContext, Option[PresentationRecord]]

def getPresentationRecordsByStates(
ignoreWithZeroRetries: Boolean,
limit: Int,
states: PresentationRecord.ProtocolState*
): RIO[WalletAccessContext, Seq[PresentationRecord]]
): URIO[WalletAccessContext, Seq[PresentationRecord]]

def getPresentationRecordsByStatesForAllWallets(
ignoreWithZeroRetries: Boolean,
limit: Int,
states: PresentationRecord.ProtocolState*
): Task[Seq[PresentationRecord]]
): UIO[Seq[PresentationRecord]]

def getPresentationRecordByThreadId(thid: DidCommID): RIO[WalletAccessContext, Option[PresentationRecord]]
def findPresentationRecordByThreadId(thid: DidCommID): URIO[WalletAccessContext, Option[PresentationRecord]]

def updatePresentationRecordProtocolState(
recordId: DidCommID,
from: PresentationRecord.ProtocolState,
to: PresentationRecord.ProtocolState
): RIO[WalletAccessContext, Int]
): URIO[WalletAccessContext, Unit]

def updateWithRequestPresentation(
recordId: DidCommID,
request: RequestPresentation,
protocolState: ProtocolState
): RIO[WalletAccessContext, Int]
): URIO[WalletAccessContext, Unit]

def updateWithProposePresentation(
recordId: DidCommID,
request: ProposePresentation,
protocolState: ProtocolState
): RIO[WalletAccessContext, Int]
): URIO[WalletAccessContext, Unit]

def updateWithPresentation(
recordId: DidCommID,
presentation: Presentation,
protocolState: ProtocolState
): RIO[WalletAccessContext, Int]
): URIO[WalletAccessContext, Unit]

def updatePresentationWithCredentialsToUse(
recordId: DidCommID,
credentialsToUse: Option[Seq[String]],
protocolState: ProtocolState
): RIO[WalletAccessContext, Int]
): URIO[WalletAccessContext, Unit]

def updateSDJWTPresentationWithCredentialsToUse(
recordId: DidCommID,
credentialsToUse: Option[Seq[String]],
sdJwtClaimsToDisclose: Option[SdJwtCredentialToDisclose],
protocolState: ProtocolState
): RIO[WalletAccessContext, Int]
): URIO[WalletAccessContext, Unit]

def updateAnoncredPresentationWithCredentialsToUse(
recordId: DidCommID,
anoncredCredentialsToUseJsonSchemaId: Option[String],
anoncredCredentialsToUse: Option[AnoncredCredentialProofs],
protocolState: ProtocolState
): RIO[WalletAccessContext, Int]
): URIO[WalletAccessContext, Unit]

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

0 comments on commit 1fd43a8

Please sign in to comment.