대부분 맛의 문제입니다. 난 당신이 또한 오류
val decider: Decider = {
case ex =>
ex.printStackTrace()
Supervision.Stop // Passes error down to subscriber
}
를 처리하고 다음 중 하나 materializer
에서 사용하는
Decider
을 지정할 수 있습니다 일반적으로
Future[Try[HttpResponse]]
에
Future[HttpResponse]
변환 및 플로우 기반 클라이언트를 사용하는 경우 다음
response.flatMap { tryResp =>
tryResp match {
case Success(res) =>
res.status match {
case OK =>
// Unmarshal response here into Future[Something]
case Found =>
// Handle redirect by calling requestBlhBlah() again with anotehr URI
case _ =>
// I got status code I didn't expect so I wrap it along with body into Future failure
Unmarshal(res.entity).to[String].flatMap { body =>
Future.failed(new IOException(s"The response status is ${res.status} [${request.uri}] and response body is $body"))
}
}
case Failure(ex) =>
Future.failed(ex)
}
}
로 처리 .withAttributes(ActorAttributes.supervisionStrategy(decider))
,369 통해
implicit val materializer = ActorMaterializer(ActorMaterializerSettings(system).withSupervisionStrategy(decider))(system)
또는 플로우 별 기반에서
Future
실패마다 처리 방법은 사용자에게 달려 있습니다. recoverWith
을 사용하여 오류를 다른 것으로 변환하거나 Future.onFailure
에 로그인하십시오.
Ahm ... 나는 똑같은 일을하지만 Try 대신에 하나를 사용합니다. 최종 결과는 모든 것이 정상이면 Future [Something]이 반환되고 그렇지 않으면 실패한 미래가 원래 응답 (Future [HttpResponse]) 또는 대상 서비스에서 알려진 오류 응답에 대해 정의한 일부 고객 예외 – EugeneMi
그러나 (1) 미래에 반환 된 예외는 관리자에게 전파되지 않으므로 결코 처리되지 않습니다. (2) We 클라이언트가 반환 할 수있는 예외를 알아야하며 처리하거나 로그에 기록해야합니다. – EugeneMi
내 대답에 더 많은 것을 추가했습니다. – expert