I find the Success case is frequently buried in a match of many errors and one success. Is there another way to write this more cleanly such that sucess stands out perhaps by having all errors in a partial function? Or perhaps, there is another way to write it but just cleaner. I am in general just looking for other ideas/solutions that could be done.
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")
}