I have a block of code as shown below to handle some exceptions, i use if-else statement but i don't like them nested within each other, wondering if it is possible to use pattern match to make it nicer?
try {
if (response.code < 200 || response.code > 299) {
throw new SearchClientFailure(s"API request failed with code ${response.code}, body ${response.body}")
} else {
if (isExceeded(response.body)) {
throw new SearchClientFailure("Exceed limit")
} else {
response.body
}
}
} catch {
case e: SearchClientFailure =>
if (queries.isEmpty) {
throw new SearchClientFailure
} else {
logger.warn(s"Failed to update the queries: ${e.message}")
queries
}
case _ =>
throw new SearchClientFailure
}