Skip to content

Avoid default Accept header from HttpUrlConnection in RestTemplate with put and delete #23740

@nytro77

Description

@nytro77

Affects: 5.1.10

It seems that the RestTemplate does not handle exceptions thrown by DELETE the same way as it does for GET and POST.
HttpStatusCodeException.getResponseBodyAsString() returns whitelabel error page as HTML instead of the expected JSON.

Example from exceptional DELETE:
<html><body><h1>Whitelabel Error Page</h1><p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p><div id='created'>Tue Oct 01 15:38:04 CEST 2019</div><div>There was an unexpected error (type=Internal Server Error, status=500).</div><div>I am delete error</div></body></html>

Example from exceptional GET:
{"timestamp":"2019-10-01T13:38:04.682+0000","status":500,"error":"Internal Server Error","message":"I am get error","path":"/test"}

Reproduced in this simple Spring Boot project

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: supersededAn issue that has been superseded by anothertype: enhancementA general enhancement

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions