Skip to content

Commit

Permalink
feat: Expose Stored Error (#1276)
Browse files Browse the repository at this point in the history
Signed-off-by: Bassam Riman <[email protected]>
  • Loading branch information
CryptoKnightIOG authored Aug 2, 2024
1 parent 1c9cbd0 commit 758fe87
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.hyperledger.identus.connect.controller.http

import org.hyperledger.identus.api.http.Annotation
import org.hyperledger.identus.api.http.{Annotation, ErrorResponse}
import org.hyperledger.identus.connect.controller.http.Connection.annotations
import org.hyperledger.identus.connect.controller.http.Connection.annotations.goalcode
import org.hyperledger.identus.connect.core.model
import org.hyperledger.identus.connect.core.model.ConnectionRecord.Role
import org.hyperledger.identus.shared.models.{FailureInfo, StatusCode}
import sttp.model.Uri
import sttp.tapir.{Schema, Validator}
import sttp.tapir.Schema.annotations.{description, encodedExample, validate}
Expand Down Expand Up @@ -54,6 +55,9 @@ case class Connection(
@description(annotations.metaRetries.description)
@encodedExample(annotations.metaRetries.example)
metaRetries: Int,
@description(annotations.metaLastFailure.description)
@encodedExample(annotations.metaLastFailure.example)
metaLastFailure: Option[ErrorResponse] = None,
@description(annotations.self.description)
@encodedExample(annotations.self.example)
self: String = "",
Expand Down Expand Up @@ -92,6 +96,7 @@ object Connection {
createdAt = domain.createdAt.atOffset(ZoneOffset.UTC),
updatedAt = domain.updatedAt.map(_.atOffset(ZoneOffset.UTC)),
metaRetries = domain.metaRetries,
metaLastFailure = domain.metaLastFailure.map(failure => ErrorResponse.failureToErrorResponseConversion(failure)),
self = domain.id.toString,
kind = "Connection",
)
Expand Down Expand Up @@ -199,6 +204,13 @@ object Connection {
example = 5
)

object metaLastFailure
extends Annotation[ErrorResponse](
description = "The last failure if any.",
example =
ErrorResponse.failureToErrorResponseConversion(FailureInfo("Error", StatusCode.NotFound, "Not Found"))
)

object self
extends Annotation[String](
description = "The reference to the connection resource.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.hyperledger.identus.issue.controller.http

import org.hyperledger.identus.api.http.Annotation
import org.hyperledger.identus.api.http.{Annotation, ErrorResponse}
import org.hyperledger.identus.issue.controller.http.IssueCredentialRecord.annotations
import org.hyperledger.identus.mercury.model.{AttachmentDescriptor, Base64}
import org.hyperledger.identus.pollux.core.model.IssueCredentialRecord as PolluxIssueCredentialRecord
import org.hyperledger.identus.shared.models.{FailureInfo, StatusCode}
import sttp.tapir.{Schema, Validator}
import sttp.tapir.json.zio.schemaForZioJsonValue
import sttp.tapir.Schema.annotations.{description, encodedExample, validate}
Expand Down Expand Up @@ -58,7 +59,10 @@ final case class IssueCredentialRecord(
issuingDID: Option[String] = None,
@description(annotations.metaRetries.description)
@encodedExample(annotations.metaRetries.example)
metaRetries: Int
metaRetries: Int,
@description(annotations.metaLastFailure.description)
@encodedExample(annotations.metaLastFailure.example)
metaLastFailure: Option[ErrorResponse] = None
)

object IssueCredentialRecord {
Expand Down Expand Up @@ -95,7 +99,8 @@ object IssueCredentialRecord {
vc
}
}),
metaRetries = domain.metaRetries
metaRetries = domain.metaRetries,
metaLastFailure = domain.metaLastFailure.map(failure => ErrorResponse.failureToErrorResponseConversion(failure)),
)

given Conversion[PolluxIssueCredentialRecord, IssueCredentialRecord] = fromDomain
Expand Down Expand Up @@ -244,6 +249,13 @@ object IssueCredentialRecord {
example = 5
)

object metaLastFailure
extends Annotation[ErrorResponse](
description = "The last failure if any.",
example =
ErrorResponse.failureToErrorResponseConversion(FailureInfo("Error", StatusCode.NotFound, "Not Found"))
)

}

given encoder: JsonEncoder[IssueCredentialRecord] =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.hyperledger.identus.presentproof.controller.http

import org.hyperledger.identus.api.http.Annotation
import org.hyperledger.identus.api.http.{Annotation, ErrorResponse}
import org.hyperledger.identus.mercury.model.Base64
import org.hyperledger.identus.pollux.core.model.PresentationRecord
import org.hyperledger.identus.presentproof.controller.http.PresentationStatus.annotations
import org.hyperledger.identus.shared.models.{FailureInfo, StatusCode}
import sttp.tapir.{Schema, Validator}
import sttp.tapir.Schema.annotations.{description, encodedExample, validate}
import zio.json.{DeriveJsonDecoder, DeriveJsonEncoder, JsonDecoder, JsonEncoder}
Expand Down Expand Up @@ -34,7 +35,10 @@ final case class PresentationStatus(
connectionId: Option[String] = None,
@description(annotations.metaRetries.description)
@encodedExample(annotations.metaRetries.example)
metaRetries: Int
metaRetries: Int,
@description(annotations.metaLastFailure.description)
@encodedExample(annotations.metaLastFailure.example)
metaLastFailure: Option[ErrorResponse] = None
)

object PresentationStatus {
Expand All @@ -56,7 +60,8 @@ object PresentationStatus {
proofs = Seq.empty,
data = data,
connectionId = domain.connectionId,
metaRetries = domain.metaRetries
metaRetries = domain.metaRetries,
metaLastFailure = domain.metaLastFailure.map(failure => ErrorResponse.failureToErrorResponseConversion(failure)),
)
}

Expand Down Expand Up @@ -132,6 +137,13 @@ object PresentationStatus {
description = "The maximum background processing attempts remaining for this record",
example = 5
)

object metaLastFailure
extends Annotation[ErrorResponse](
description = "The last failure if any.",
example =
ErrorResponse.failureToErrorResponseConversion(FailureInfo("Error", StatusCode.NotFound, "Not Found"))
)
}

given encoder: JsonEncoder[PresentationStatus] =
Expand Down

0 comments on commit 758fe87

Please sign in to comment.