I'm not sure I'd write the code this way; it's hard to follow (in addition to not working in its original form).
I'd rather go for something like
def doSomething(e: Exception) = { /* whatever */ }
something match {
case sae: ServerApiException if (sae.statusCode == 401) => doSomething(sae)
case ue: UnauthorizedException => doSomething(ue)
}
to avoid duplicate code. Or you could use options:
(something match {
case sae: ServerApiException if (sae.statusCode == 401) => Some(sae)
case ue: UnauthorizedException => Some(ue)
case _ => None
}).foreach(e => /* do something */ )
if you prefer to write the method afterwards. But I think the first way is likely the clearest.