在下面的方法中,只有来自 burnService.execute 的异常被捕获。来自 EarnService.execute 的任何异常都不会被捕获。如果我将 EarnService,execute 移动到理解的顶部,则会捕获 EarnService 的错误,但不会捕获 burnService 的错误。
private def processSearchItems(
processedValuesCtx: OffersProcessedValuesCtx
): Future[Either[APIError, Seq[OfferV3Response]]] = {
implicit val baseInfo: BaseInfo = BaseInfo.apply(this)
val searchResults = processedValuesCtx.req.requestWrapperInternal.offers.searchResults
// Process the search results
val result = searchResults.map { searchResult =>
try {
val searchItem = enrichSearchItemWithPricingTokenData(searchResult)
val searchItemProcessedValues = buildProcessedValues(searchItem, processedValuesCtx)
(for {
burnResponse <- EitherT(
burnService.execute(
processedValuesCtx,
searchItemProcessedValues
)
)
enrichedProcessedValuesAfterBurn =
updateItemProcessedValuesAfterBurn(processedValuesCtx, burnResponse, searchItemProcessedValues)
earnResponse <- EitherT(
earnService.execute(
processedValuesCtx,
enrichedProcessedValuesAfterBurn
)
)
splitTenders <- EitherT(
splitTenderResponseTransformer
.buildSplitTenderResponse(
burnResponse,
earnResponse,
processedValuesCtx,
searchItemProcessedValues
)
)
} yield {
val finalTenders = splitTenderResponseTransformer
.removeChargeSplitsTooCloseApart(splitTenders, processedValuesCtx)
.sortBy(_.burn.map(_.points))
OfferV3Response(
offerIdentifier = searchResult.identifier,
priceInfo = PriceInfoV3ResponseWrapper(splitTenders = finalTenders),
priceUsedToCalculate = getPriceUsedToCalculate(processedValuesCtx)
)
}).value
} catch {
case ex: Exception =>
// log and build empty response
logger.logError(
rc.toBaseLog(
s"Exception occurred!! while calculating offer :: ${ex.getMessage}",
Some(ex)
)
)
Future.successful(Right(resp))
}
}
EitherUtils.sequenceOfFutureEither(result)
}
尝试了一些方法似乎都不起作用