我发现 Success 案例经常隐藏在许多错误和一个成功的匹配中。是否有另一种方法可以更清晰地编写此代码,以使成功可能通过在部分函数中包含所有错误而脱颖而出?或者,也许还有另一种写法,但更简洁。我一般只是在寻找可以完成的其他想法/解决方案。
results.responseCode match {
case Success =>
// TODO make this less smelly. can results.results be None?
val searchResults = results.results.get.results
SomeService.getUsersFromThriftResults(
userRepo,
searchResults,
Seq(WithCounts)) map { userResults =>
val renderableStatuses = getStatuses(searchResults, userResults.userMap)
new JsonAction(transformedQuery, renderableStatuses)
}
case ErrorInvalidQuery =>
throw new SomeBadRequestException("invalid query")
case ErrorOverCapacity |
ErrorTimeout =>
throw new SomeServiceUnavailableException("service unavailable")
//TODO: take care of these errors differently
// case ErrorInvalidWorkflow |
// ErrorBackendFailure |
// ErrorEventNotFound |
// PartialSuccess |
case _ =>
throw new SomeApplicationException("internal server error")
}