Skip to content

AsyncRestTemplate should wrap RuntimeExceptions in ExecutionException [SPR-13413] #17992

@spring-projects-issues

Description

@spring-projects-issues

Lukas Krecan opened SPR-13413 and commented

We are migrating to RestTemplate and for backward compatibility reasons we have custom ResponseErrorHandler that throws RuntimExceptions. AsyncRestTemplate uses ResponseExtractorFuture which wraps IOExceptions to ExecutionException. Unfortunately it does not do the same for runtime exceptions which in turn causes different problems (for example response "caching" in ListenableFutureAdapters does not work)

It concerns this code from ResponseExtractorFuture (see comments inside)

     @Override
protected final T adapt(ClientHttpResponse response) throws ExecutionException {
     try {
          if (!getErrorHandler().hasError(response)) {
                   logResponseStatus(this.method, this.url, response);
          }
          else {
                   handleResponseError(this.method, this.url, response);  // throws Runtime exception
          }
          return convertResponse(response);
     }
     catch (IOException ex) { // here I suggest to catch RuntimeException as well
          throw new ExecutionException(ex);
     }
     finally {
          if (response != null) {
                   response.close();
          }
     }
}

Affects: 4.1.6

Issue Links:

Referenced from: commits 856561f, de0f3ae, 3402c13, 2bb7164

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions