From 123cf05df84898fa45dc9c85b98ec5261af27671 Mon Sep 17 00:00:00 2001 From: Bassam Riman Date: Tue, 30 Jul 2024 18:34:02 -0400 Subject: [PATCH] ATL-6933: Expose Stored Error Signed-off-by: Bassam Riman --- .../connect/controller/http/Connection.scala | 14 +++++++++++++- .../http/IssueCredentialRecord.scala | 18 +++++++++++++++--- .../controller/http/PresentationStatus.scala | 18 +++++++++++++++--- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/connect/controller/http/Connection.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/connect/controller/http/Connection.scala index aa05512b0b..b402ca0131 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/connect/controller/http/Connection.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/connect/controller/http/Connection.scala @@ -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} @@ -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 = "", @@ -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", ) @@ -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.", diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/issue/controller/http/IssueCredentialRecord.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/issue/controller/http/IssueCredentialRecord.scala index 1207bed5fe..f8f45cc7a3 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/issue/controller/http/IssueCredentialRecord.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/issue/controller/http/IssueCredentialRecord.scala @@ -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} @@ -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 { @@ -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 @@ -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] = diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/presentproof/controller/http/PresentationStatus.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/presentproof/controller/http/PresentationStatus.scala index 48d7c9010d..f9eeeac563 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/presentproof/controller/http/PresentationStatus.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/presentproof/controller/http/PresentationStatus.scala @@ -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} @@ -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 { @@ -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)), ) } @@ -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] =