The content-type for exception reported by server is text/html. Can it be changed?

When there is an exception, the content-type is text/html. Can it be changed to text/xml or application/xml? How?

I’m using Remoting SDK for Delphi with TROSOAPMessage.

Hi,

you can use the OnHTTPRequestDone event of plain http server.

note: it was added in .1595

1 Like

How can I identify that this is the exception?
do not want to set all responses to application/xml some responses should be text/html.

Hi,

Usually you can detect error by ErrorCode = 500 (if SendExceptionsAs500 is set) or HTTP_500_error_invalid_path message .

also errors are put between <font size="7"> and </font> tags:

  procedure WriteUTF8Error(aHeader: string; aBody: string = '');
  var
    lh: string;
    b: TBytes;
  begin
    lh := '<font size="7">' + HTTP_EscapeSpecialChars(aHeader) + '</font>';
    if aBody <> '' then lh := lh + '<br />' + HTTP_EscapeSpecialChars(aBody);
    if aResponseStream = nil then aResponseStream := TROBinaryMemoryStream.Create;
    b := StringToUTF8Bytes(lh);
    aResponseStream.Write(b, Length(b));
    aResponse.ContentType := id_ContentType_text_html_charset_utf8;
  end;

  procedure WriteError(aMessage: string);
  begin
    if Assigned(aResponseStream) then aResponseStream.Size := 0;
    aResponse.ContentType := id_ContentType_text_html_charset_utf8;
    if fSendExceptionsAs500 then begin
      aResponse.Code := HTTP_500_code;
      WriteUTF8Error(HTTP_500_error_invalid_path);
    end
    else begin
      aResponse.Code := HTTP_200_code;
      WriteUTF8Error(HTTP_500_error_invalid_path, aMessage);
    end;
  end;

1 Like