Skip to content

Error status code set by handler interceptor overriden with status code 500 #20025

Closed
@abadea-atl

Description

@abadea-atl

Spring Boot 2.2.4

  1. Have a controller method with @Produces("application/x-protobuf").
  2. Have a handler interceptor that writes status code 401 to the response when the controller method from Fixed name of annotation and a typo in the code. #1 is invoked.

This returns an HTTP response with status code 500 and no body. After the fix of #19522, I expected status code 401 to be returned.

This seems to happen due to this code in AbstractMessageConverterMethodProcessor around line 316:

if (isContentTypePreset || !CollectionUtils.isEmpty(producibleMediaTypes)) {
    throw new HttpMessageNotWritableException(
            "No converter for [" + valueType + "] with preset Content-Type '" + contentType + "'");
}
throw new HttpMediaTypeNotAcceptableException(this.allSupportedMediaTypes);

producibleMediaTypes contains the controller's application/x-protobuf, so HttpMessageNotWritableException is thrown, which is turned into a 500 status code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions