Skip to content

Allow use of custom (binary) exception classifier in RestTemplateBuilder #441

Closed
@morulay

Description

@morulay

Some DBs hint with specific vendor code or SQLState if a DB request/transaction could be retried in case of exception, e.g. exception instanceof SQLException sqlException && "12345".equals(sqlException.getErrorCode()) . spring-retry can handle this case either with:

  • Utility class holding the predicate (classifier) + SPeL and ExpressionRetryPolicy - not very fast due to the expression evaluation
  • Assembling manually RestTemplate with custom RetryPolicy - more error prone and lacks the convenience of RetryTemplate.builder()

Both solutions have drawbacks and mostly lacks the convenience of RetryTemplate.builder().

Do you think it is possible to allow the use of custom (binary) exception classifier in RetryTemplate.builder(). Here is an example to depict the idea:

RetryTemplate retryTemplate = RetryTemplate.builder()
  .maxAtmepts(3)
  .customExceptionClassifier(classifiable -> classifiable instanceof SQLException sqlException
      && "retry_vendor_code".equals(sqlException.getErrorCode()))
  .build()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions