1
내가 외부 API를 호출하고 내가 OK과 다른 상태 코드의 경우 사용자에게 "있는 그대로"결과를 반환하려는 실패한 경우 보내는 응답 응답 :akka-HTTP
val connectionFlow: Flow[HttpRequest, HttpResponse, Future[Http.OutgoingConnection]] =
Http().outgoingConnection("akka.io")
def responseFuture: Future[HttpResponse] =
Source.single(HttpRequest(uri = "/"))
.via(connectionFlow)
.runWith(Sink.head)
val fooRoutes = path("foo"){
get {
complete(
responseFuture.flatMap{ response =>
case OK =>
Unmarshal(response.entity.withContentType(ContentTypes.`application/json`)).to[Foo]
case _ => response //fails
})}}
방법을 내가 하나가 onComplete
지시어를 사용 할 수있는이 문제를 해결하는 다른 유효한 방법이있을 수 있습니다 생각한다
Unmarshal(response.entity).to[String].flatMap { body =>
Future.failed(new IOException(s"The response status is ${response.status} response body is $body"))}
감사합니다. 유효한 해결책으로 보입니다. – igx