I have a REST service that can produce responses in either JSON or XML, as defined by the produces = {"application/xml", "application/json"} parameter.

The goal is to ensure that when an exception occurs, the error response is returned using the same media type that the client requested (e.g., XML for an XML request, JSON for a JSON request).

However, the current behavior during exception handling is to overwrite the original produces list. If a custom exception handler does not explicitly declare its own produces parameter, this results in an empty list of supported media types, which can lead to unexpected behavior.

My proposal is to modify this logic so that the original produces list from the endpoint is preserved and used as a fallback whenever the exception handler itself does not specify one.

Comment From: bclozel

Duplicates #35587

Comment From: bclozel

@IMurzich there is no need to create an issue for the pull request you already submitted. Please sign the DCO as requested in the review comments.

Comment From: IMurzich

Hi, @bclozel ! It isn't duplicate. #35587 fixes produces list order. This issue adds reuse produces list.

Comment From: bclozel

I have just declined #35765 with the following reason:

Thanks for the proposal, but this is a long standing behavior and we want to keep it, see #20865.

The error handling method does not necessarily produce the same content-type as the handler that errored in the first place. Content negotiation has to be considered again.