Can anyone help me with this please?
I have the following in my route:
val result = (requestHandler ? RequestHandler.AskForStatus).mapTo[PimpedResult[(StatusCode, Result[StatusDTO])]]
onSuccess(result) {
case _ => complete(result)
}
The mapTo is really just to assist my debugging. The result could be a Result[StatusDTO] or a PimpedResult.
Anyway, I get the following error on the complete call:
type mismatch; found : scala.concurrent.Future[PimpedResult[(akka.http.scaladsl.model.StatusCode, Result[StatusDTO])]] (which expands to) scala.concurrent.Future[PimpedResult[(akka.http.scaladsl.model.StatusCode, scala.util.Either[APIError,StatusDTO])]] required: akka.http.scaladsl.marshalling.ToResponseMarshallable
I added the following after the mapTo:
val prm = implicitly[Future[PimpedResult[(StatusCode, Result[StatusDTO])]] => ToResponseMarshallable]
and that line gets this error:
Multiple markers at this line:
not enough arguments for method implicitly: (implicit e: scala.concurrent.Future[PimpedResult[(akka.http.scaladsl.model.StatusCode, Result[StatusDTO])]] ⇒ akka.http.scaladsl.marshalling.ToResponseMarshallable)scala.concurrent.Future[PimpedResult[(akka.http.scaladsl.model.StatusCode, Result[StatusDTO])]] ⇒ akka.http.scaladsl.marshalling.ToResponseMarshallable. Unspecified value parameter e.
No implicit view available from scala.concurrent.Future[PimpedResult[(akka.http.scaladsl.model.StatusCode, Result[StatusDTO])]] ⇒ akka.http.scaladsl.marshalling.ToResponseMarshallable.
Here is the custom marshaller. I know it's in scope because the errorMarshaller works in the case where the response is Result[StatusDTO] rather than PimpedResult
trait APICustomMarshallers {
implicit def errorMarshaller[T](
implicit translator: ErrorTranslator[T],
statusCodeMapper: ErrorToStatusCodeMapper,
m: ToEntityMarshaller[T]): ToResponseMarshaller[APIError] = {
val base = PredefinedToResponseMarshallers.fromStatusCodeAndHeadersAndValue
val result = base.compose {
error: APIError => (statusCodeMapper.orElse(ErrorToStatusCodeMapper.Default)(error), DefaultHttpHeaders.NoCacheHeaders, translator(error))
}
result
}
implicit def statusMarshaller[T](implicit m: ToEntityMarshaller[T]): ToResponseMarshaller[PimpedResult[(StatusCode, T)]] = {
val base = PredefinedToResponseMarshallers.fromStatusCodeAndHeadersAndValue // Needs the entity marshaller
val result = base.compose {
pimpedResult: PimpedResult[(StatusCode, T)] =>
pimpedResult.result match {
case Right(response) => (response._1, DefaultHttpHeaders.NoCacheHeaders, response._2)
case _ => throw new RuntimeException("StatusMarshaller got invalid PimpedResult")
}
}
result
}
}
Thanks for any help.