Skip to content

Commit

Permalink
[DPP-619][Self-service error codes] Adopt error codes in ApiVersionSe…
Browse files Browse the repository at this point in the history
…rvice (#11303)

CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
pbatko-da authored Oct 20, 2021
1 parent 5f5af30 commit da27a1e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private[daml] object ApiServices {
ApiTransactionService.create(ledgerId, transactionsService, metrics, errorsVersionsSwitcher)

val apiLedgerIdentityService =
ApiLedgerIdentityService.create(() => identityService.getLedgerId())
ApiLedgerIdentityService.create(() => identityService.getLedgerId(), errorsVersionsSwitcher)

val apiVersionService =
ApiVersionService.create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

package com.daml.platform.apiserver.services

import com.daml.error.{DamlContextualizedErrorLogger, ContextualizedErrorLogger}
import com.daml.error.{
ContextualizedErrorLogger,
DamlContextualizedErrorLogger,
ErrorCodesVersionSwitcher,
}
import com.daml.ledger.api.domain.LedgerId
import com.daml.ledger.api.v1.ledger_identity_service.LedgerIdentityServiceGrpc.{
LedgerIdentityService => GrpcLedgerIdentityService
Expand All @@ -22,22 +26,25 @@ import scalaz.syntax.tag._
import scala.concurrent.{ExecutionContext, Future}

private[apiserver] final class ApiLedgerIdentityService private (
getLedgerId: () => Future[LedgerId]
getLedgerId: () => Future[LedgerId],
errorCodesVersionSwitcher: ErrorCodesVersionSwitcher,
)(implicit executionContext: ExecutionContext, loggingContext: LoggingContext)
extends GrpcLedgerIdentityService
with GrpcApiService {
private val logger = ContextualizedLogger.get(this.getClass)
private implicit val contextualizedErrorLogger: ContextualizedErrorLogger =
new DamlContextualizedErrorLogger(logger, loggingContext, None)

private val errorFactories = ErrorFactories(errorCodesVersionSwitcher)

@volatile var closed = false

override def getLedgerIdentity(
request: GetLedgerIdentityRequest
): Future[GetLedgerIdentityResponse] = {
logger.info(s"Received request for ledger identity: $request")
if (closed)
Future.failed(ErrorFactories.serviceNotRunning(None))
Future.failed(errorFactories.serviceNotRunning(None))
else
getLedgerId()
.map(ledgerId => GetLedgerIdentityResponse(ledgerId.unwrap))
Expand All @@ -52,11 +59,12 @@ private[apiserver] final class ApiLedgerIdentityService private (

private[apiserver] object ApiLedgerIdentityService {
def create(
getLedgerId: () => Future[LedgerId]
getLedgerId: () => Future[LedgerId],
errorCodesVersionSwitcher: ErrorCodesVersionSwitcher,
)(implicit
executionContext: ExecutionContext,
loggingContext: LoggingContext,
): ApiLedgerIdentityService with BindableService = {
new ApiLedgerIdentityService(getLedgerId)
new ApiLedgerIdentityService(getLedgerId, errorCodesVersionSwitcher)
}
}

0 comments on commit da27a1e

Please sign in to comment.