【发布时间】:2014-10-14 03:25:42
【问题描述】:
我发现成功案例经常隐藏在许多错误和一个成功的匹配中。是否有另一种方法可以更清晰地编写此代码,以使成功可能通过在部分函数中包含所有错误而脱颖而出?或者,也许还有另一种写法,但更简洁。一般来说,我只是在寻找可以完成的其他想法/解决方案。
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")
}
【问题讨论】:
-
我不明白为什么平面版已经不是非常好和简单了。