Error returned by ReturnOverrides does not render the proper error template

I am using a javascript pre middleware to return a 400 response if a required url parameter is missing.

    // should fail and stop chain
    request.ReturnOverrides.ResponseCode = 400;
    request.ReturnOverrides.ResponseError = "Invalid app Id";

The endpoint am using expects an xml body and has the right content-type: text/xml header set. The problem I have is that this always returns a json error body, where I expect that my error_400.xml will be rendered.
Anything am missing, maybe about the intended use of ReturnOverrides?