THRIFT-5384 Improved error message for HTTP transports
Client: Delphi
Patch: Jens Geyer
diff --git a/lib/delphi/src/Thrift.Protocol.pas b/lib/delphi/src/Thrift.Protocol.pas
index d5a7587..aa12ad3 100644
--- a/lib/delphi/src/Thrift.Protocol.pas
+++ b/lib/delphi/src/Thrift.Protocol.pas
@@ -833,6 +833,7 @@
 begin
   Reset;
   Init( result);
+
   size := ReadI32;
   if (size < 0) then begin
     version := size and Integer( VERSION_MASK);
@@ -842,14 +843,20 @@
     result.Type_ := TMessageType( size and $000000ff);
     result.Name := ReadString;
     result.SeqID := ReadI32;
-  end
-  else begin
-    if FStrictRead then begin
-      raise TProtocolExceptionBadVersion.Create('Missing version in readMessageBegin, old client?' );
-    end;
+    Exit;
+  end;
+
+  try
+    if FStrictRead
+    then raise TProtocolExceptionBadVersion.Create('Missing version in readMessageBegin, old client?' );
+
     result.Name := ReadStringBody( size );
     result.Type_ := TMessageType( ReadByte );
     result.SeqID := ReadI32;
+  except
+    if CharUtils.IsHtmlDoctype(size)
+    then raise TProtocolExceptionInvalidData.Create('Remote end sends HTML instead of data')
+    else raise; // something else
   end;
 end;