You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The org.springframework.web.client.DefaultRestClient#readWithMessageConverters method from spring-web:7.0.8 is hiding I/O Exceptions (SocketTimeouts from connectTimeout/readTimeout) as a RestClientException with an unrelated content-type incompatibility message:
thrownewRestClientException("Error while extracting response for type [" + ResolvableType.forType(bodyType) + "] and content type [" + contentType + "]", cause);
For example a SocketTimeout exception triggered by a readTimeout set in a client configured with Accept/Content-Type headers for "application/json", throws a RestClientException with the message:
"Error while extracting response for type [MyServiceResponse] and content type [application/octet-stream]"
This message is misleading, causing confusion in the actual underlying issue. Ideally if the issue is I/O related, the readWithMessageConverters method should throw a ResourceAccessException with the proper message.
根因:DefaultRestClient.readWithMessageConverters 的 catch 块把 UncheckedIOException | IOException | HttpMessageNotReadableException 统一包成 RestClientException("Error while extracting response for type [...] and content type [...]", cause)——即使 cause 是 I/O 异常(如 SocketTimeout),消息却指向 content type,产生误导。
Hi Spring team, I would like to work on this issue if it is open for contribution. Could you please assign it to me?
I saw the proposed direction above around preserving the I/O failure as a ResourceAccessException from DefaultRestClient.readWithMessageConverters. Before I start, I will wait for confirmation that this is the desired fix and add focused coverage for the I/O exception case.
Gentle ping on this. I am still interested in working on a focused fix for preserving I/O failures as ResourceAccessException from DefaultRestClient.readWithMessageConverters, with regression coverage. Please let me know if that direction is acceptable before I start.
Activity
fudianchn commentedon Jul 26, 2026
定位了根因并有一个向后兼容的修复方案(暂未提 PR,因本地 Gradle 构建受网络阻断无法验证;先贴方案供参考)。
根因:
DefaultRestClient.readWithMessageConverters的 catch 块把UncheckedIOException | IOException | HttpMessageNotReadableException统一包成RestClientException("Error while extracting response for type [...] and content type [...]", cause)——即使 cause 是 I/O 异常(如 SocketTimeout),消息却指向 content type,产生误导。修复:cause 为
IOException时改抛ResourceAccessException(I/O 专用消息)。这是向后兼容的,因为ResourceAccessException extends RestClientException(子类),捕获RestClientException的调用方仍能捕获。而且该类里已有同样用ResourceAccessException表达 I/O 错误的先例(createResourceAccessException)。测试思路:mock
ClientHttpResponse.getBody()抛IOException,retrieve().body(String.class)应抛ResourceAccessException(而非带 content-type 消息的RestClientException)。akg268 commentedon Aug 9, 2026
Hi Spring team, I would like to work on this issue if it is open for contribution. Could you please assign it to me?
I saw the proposed direction above around preserving the I/O failure as a
ResourceAccessExceptionfromDefaultRestClient.readWithMessageConverters. Before I start, I will wait for confirmation that this is the desired fix and add focused coverage for the I/O exception case.akg268 commentedon Aug 23, 2026
Gentle ping on this. I am still interested in working on a focused fix for preserving I/O failures as ResourceAccessException from DefaultRestClient.readWithMessageConverters, with regression coverage. Please let me know if that direction is acceptable before I start.
bclozel commentedon Aug 23, 2026
@akg268 this is not yet triaged and we already received two PRs for this.