Skip to content

Make is easier to use TestRestTemplate with a custom ResponseErrorHandler #7265

@MateuszRasinski

Description

@MateuszRasinski

Custom error handler set using RestTemplateBuilder bean or using the configuration TestRestTemplateConfiguration from Spring Boot Reference Guide is overriden by TestRestTemplate.NoOpResponseErrorHandler.

Specifically, when using the following class:

class CustomResponseErrorHandler extends DefaultResponseErrorHandler {
    // implementation
}

in the configuration of the builder:

ResponseErrorHandler customErrorHandler = new CustomResponseErrorHandler();
RestTemplateBuilder builder = builderProvider.getIfAvailable()
                                             .errorHandler(customErrorHandler);

The following line is false:

new TestRestTemplate(builder.build()).getRestTemplate().getErrorHandler().equals(customErrorHandler)

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions