From 888ebb4b484224d9c73674cffdf7d00777cfb4dc Mon Sep 17 00:00:00 2001 From: Fabio Pinheiro Date: Fri, 7 Jun 2024 03:32:05 +0200 Subject: [PATCH] feat: Remove double Error logs in DIDController (#1140) --- .../identus/castor/core/model/did/w3c/package.scala | 8 ++++---- .../identus/castor/core/model/error/package.scala | 8 ++++++-- .../identus/castor/core/service/DIDService.scala | 9 +++------ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/castor/src/main/scala/org/hyperledger/identus/castor/core/model/did/w3c/package.scala b/castor/src/main/scala/org/hyperledger/identus/castor/core/model/did/w3c/package.scala index af2ffbd8a8..80eb7fd719 100644 --- a/castor/src/main/scala/org/hyperledger/identus/castor/core/model/did/w3c/package.scala +++ b/castor/src/main/scala/org/hyperledger/identus/castor/core/model/did/w3c/package.scala @@ -25,10 +25,10 @@ package object w3c { } .mapBoth( { - case DLTProxyError(_) => - DIDResolutionErrorRepr.InternalError("Error occurred while connecting to Prism Node") - case UnexpectedDLTResult(_) => - DIDResolutionErrorRepr.InternalError("Unexpected result obtained from Prism Node") + case ex: DLTProxyError => + DIDResolutionErrorRepr.InternalError(s"Error occurred while connecting to Prism Node: ${ex.getMessage}") + case UnexpectedDLTResult(msg) => + DIDResolutionErrorRepr.InternalError(s"Unexpected result obtained from Prism Node: $msg") case ValidationError(e) => DIDResolutionErrorRepr.InvalidDID(e.toString) }, _.toRight(DIDResolutionErrorRepr.NotFound) diff --git a/castor/src/main/scala/org/hyperledger/identus/castor/core/model/error/package.scala b/castor/src/main/scala/org/hyperledger/identus/castor/core/model/error/package.scala index c8922e6bb0..001db37e68 100644 --- a/castor/src/main/scala/org/hyperledger/identus/castor/core/model/error/package.scala +++ b/castor/src/main/scala/org/hyperledger/identus/castor/core/model/error/package.scala @@ -4,7 +4,9 @@ package object error { sealed trait DIDOperationError object DIDOperationError { - final case class DLTProxyError(cause: Throwable) extends DIDOperationError + final case class DLTProxyError(msg: String, cause: Throwable) extends DIDOperationError { + def getMessage = msg + ": " + cause.getMessage() + } final case class UnexpectedDLTResult(msg: String) extends DIDOperationError final case class ValidationError(cause: OperationValidationError) extends DIDOperationError } @@ -12,7 +14,9 @@ package object error { sealed trait DIDResolutionError object DIDResolutionError { - final case class DLTProxyError(cause: Throwable) extends DIDResolutionError + final case class DLTProxyError(msg: String, cause: Throwable) extends DIDResolutionError { + def getMessage = msg + ": " + cause.getMessage() + } final case class UnexpectedDLTResult(msg: String) extends DIDResolutionError final case class ValidationError(cause: OperationValidationError) extends DIDResolutionError } diff --git a/castor/src/main/scala/org/hyperledger/identus/castor/core/service/DIDService.scala b/castor/src/main/scala/org/hyperledger/identus/castor/core/service/DIDService.scala index e65db12ccd..5e8358e7e6 100644 --- a/castor/src/main/scala/org/hyperledger/identus/castor/core/service/DIDService.scala +++ b/castor/src/main/scala/org/hyperledger/identus/castor/core/service/DIDService.scala @@ -53,8 +53,7 @@ private class DIDServiceImpl(didOpValidator: DIDOperationValidator, nodeClient: .mapError(DIDOperationError.ValidationError.apply) operationOutput <- ZIO .fromFuture(_ => nodeClient.scheduleOperations(operationRequest)) - .logError("Error scheduling Node operation") - .mapBoth(DIDOperationError.DLTProxyError.apply, _.outputs.toList) + .mapBoth(ex => DIDOperationError.DLTProxyError("Error scheduling Node operation", ex), _.outputs.toList) .map { case output :: Nil => Right(output) case _ => Left(DIDOperationError.UnexpectedDLTResult("operation result is expected to have exactly 1 output")) @@ -82,8 +81,7 @@ private class DIDServiceImpl(didOpValidator: DIDOperationValidator, nodeClient: for { result <- ZIO .fromFuture(_ => nodeClient.getOperationInfo(node_api.GetOperationInfoRequest(operationId.toProto))) - .logError("Error getting Node operation information") - .mapError(DIDOperationError.DLTProxyError.apply) + .mapError(ex => DIDOperationError.DLTProxyError("Error getting Node operation information", ex)) detail <- ZIO .fromEither(result.toDomain) .mapError(DIDOperationError.UnexpectedDLTResult.apply) @@ -100,8 +98,7 @@ private class DIDServiceImpl(didOpValidator: DIDOperationValidator, nodeClient: } result <- ZIO .fromFuture(_ => nodeClient.getDidDocument(request)) - .logError("Error resolving DID document from Node") - .mapError(DIDResolutionError.DLTProxyError.apply) + .mapError(ex => DIDResolutionError.DLTProxyError("Error resolving DID document from Node", ex)) publishedDidData <- ZIO .fromOption(result.document) .foldZIO(