Improve RetryExceptions middleware to support exception-dependent backoffs

/cc @proby