Skip to content

Spring Webflux ignores message of custom exception when annotated with @ResponseStatus #19846

@xabgesagtx

Description

@xabgesagtx

Affected component: spring-webflux
Version: 2.2.4.RELEASE

When returning a custom exception with a @ResponseStatus annotation in a controller method, spring mvc extracts the message of the exception into the error attribute message. This message will then be available in the default json response and can also be used in templates.

Spring webflux however ignores the message of the exception when it's annotated with @ResponseStatus. The only way to set a message then is via the reason parameter of the annotation.

I created a sample application with a (currently failing) WebFluxTest to demonstrate the behaviour of ignoring the message.

After some investigation in the code, I think that in DefaultErrorAttributes, when the message is determined, it's not checked if the value for the reason parameter is an empty string, which is the default value for this parameter. Therefore this empty string is always preferred to the message of the message of the exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: supersededAn issue that has been superseded by anothertype: bugA general bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions