私は、単純なアクション機能があります。内部関数を介してアクション関数に例外を返す方法はありますか?
def someActionFunc() = Action.async { request =>
myService.doSomething1().map { res =>
logger.debug(res.getMessageId)
Ok(res.getMessageId)
}.recover {
case ex =>
logger.error(s"fail:", ex)
BadRequest(s"fail with error: ${ex.getMessage}")
}
}
doSomething1
はFuture
を返し、doSomething1
に私はいくつかのオブジェクトを返し、例外が起こった他のいくつかの機能doSomething2
を呼んでいるが、私はどのように知りません
doSomething2
にしようとした
fail with error: my reason
ユーザーに返したい原因アクション機能(someActionFunc
)にdoSomething1
を通じてdoSomething2
で起こったエラーを返します
def doSomething2(someCondition: Boolean) = {
if (someCondition){
throw new RuntimeException("my reason")
}
}
が、私はアクション機能を投げるどのように私は、ユーザーに適切にエラーを返すことができ、投げ出されますか?