Skip to content

Commit

Permalink
feat: Remove double Error logs in DIDController (#1140)
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioPinheiro authored Jun 7, 2024
1 parent 5755504 commit 888ebb4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ 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
}

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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down

0 comments on commit 888ebb4

Please sign in to comment.