Error 401 needs to return json and not text plain

Hello everyone, I have an api server (Delphi) and I am receiving requests from a client and when the credentials are invalid I return a json, but the json reaches the client as text plain.
Is there a way for it to arrive as json as it was generated?
example:

procedure TServices.RORemoteDataModuleGetDispatchInfo( 
  const aTransport: IROTransport; const aMessage: IROMessage); 
var 
  HTTPInfo              : IROHTTPTransport; 
  Authorization         : string; 
  WWWAuthenticate       : String; 
  Authorization_Decoded : String; 
begin 
  try 
    if Supports(aTransport, IROHTTPTransport, HTTPInfo) then 
    begin 
      WWWAuthenticate := HTTPInfo.Headers['WWW-Authenticate']; 
      Authorization   := HTTPInfo.Headers['Authorization'].Substring(Length('Basic')+ 
        Pos('Basic ', HTTPInfo.Headers['Authorization'])); 
      Authorization_Decoded := Soap.EncdDecd.DecodeString(Authorization); 
      if Authorization_Decoded  <> (Api_User+':'+Api_Password) then 
      begin 
        raise EROHttpApiException.Create(HTTP_401_code, '{"State":"888","Message":"Descripcion"}'); 
      end; 
    end; 
  finally 
    HTTPInfo := nil; 
  end; 
end;

Hi,

all errors are written with text/plain; charset=utf-8 encoding. you can’t change it.

one exception: if client’s request is handled with HTTPServer.OnCustomResponseEvent , you can add post-processing and change everything: content type, response code, response itself, etc.

pls review Using OnCustomResponseEvent in a ROSDK Server snippet.
related topics to that snippet will contain examples of usage including HttpApi.

this will work for all requests - usual and ones via HttpApi.