the-algorithm/home-mixer/server/src/main/scala/com/twitter/home_mixer/module/PipelineFailureExceptionMapper.scala

30 lines
1.1 KiB
Scala

package com.twitter.home_mixer.module
import com.twitter.finatra.thrift.exceptions.ExceptionMapper
import com.twitter.home_mixer.{thriftscala => t}
import com.twitter.util.logging.Logging
import com.twitter.product_mixer.core.pipeline.pipeline_failure.PipelineFailure
import com.twitter.product_mixer.core.pipeline.pipeline_failure.ProductDisabled
import com.twitter.scrooge.ThriftException
import com.twitter.util.Future
import javax.inject.Singleton
@Singleton
class PipelineFailureExceptionMapper
extends ExceptionMapper[PipelineFailure, ThriftException]
with Logging {
def handleException(throwable: PipelineFailure): Future[ThriftException] = {
throwable match {
// SliceService (unlike UrtService) throws an exception when the requested product is disabled
case PipelineFailure(ProductDisabled, reason, _, _) =>
Future.exception(
t.ValidationExceptionList(errors =
Seq(t.ValidationException(t.ValidationErrorCode.ProductDisabled, reason))))
case _ =>
error("Unhandled PipelineFailure", throwable)
Future.exception(throwable)
}
}
}