Escalating exceptions in ack actors and futures in scala
I am developing a server that is a staging server between two other endpoints. So I am implementing a spray route that triggers a computation, and that computation calls an actor that invokes the spray client. The following template applies:
Client => ... => (Spray Route => Service Actor => Spray Client) => ... => remote server. I am developing exception management and am having a hard time figuring out what to do. When the remote server sends me a BadRequest or some kind of error code, I want to throw an exception that results in the client with the same type of error.
I guess my question is generally about exception handling and equalizers.
I naively believed that when I make an exception in the future, the future might cause the Fail case:
def receive = {
case SendRequest => {
val s = sender()
val call = for {
request <- ComputeRequest
result <- CallSprayClient ? request
} yield result
call onComplete {
case Success(succ) => s ! succ
case Failure(e) = throw e
}
}
}
The thing is, when ComputeRequest or CallSprayClient throws an exception, the failure case in my callback is not triggered. I looked at the observation pattern, but it seems that the exception or message causing the error does not propagate to either. In my particular case, depending on the exception, I would like to send a different HTTP response to my client, hence the escalation needed.
What development model should you use?
Thank.
source to share
No one has answered this question yet
Check out similar questions: