THRIFT-4886 More detailed error information for WinHTTP transport
Client: Delphi
Patch: Jens Geyer
diff --git a/lib/delphi/src/Thrift.Transport.WinHTTP.pas b/lib/delphi/src/Thrift.Transport.WinHTTP.pas
index d7eefa8..540865f 100644
--- a/lib/delphi/src/Thrift.Transport.WinHTTP.pas
+++ b/lib/delphi/src/Thrift.Transport.WinHTTP.pas
@@ -297,9 +297,11 @@
 
 procedure TWinHTTPClientImpl.SendRequest;
 var
-  http : IWinHTTPRequest;
+  http  : IWinHTTPRequest;
   pData : PByte;
-  len : Integer;
+  len   : Integer;
+  error : Cardinal;
+  sMsg  : string;
 begin
   http := CreateRequest;
 
@@ -307,12 +309,20 @@
   len   := FOutputMemoryStream.Size;
 
   // send all data immediately, since we have it in memory
-  if not http.SendRequest( pData, len, 0)
-  then raise TTransportExceptionUnknown.Create('send request error '+IntToStr(GetLastError));
+  if not http.SendRequest( pData, len, 0) then begin
+    error := Cardinal( GetLastError);
+    sMsg  := 'WinHTTP send error '+IntToStr(Int64(error))+' '+WinHttpSysErrorMessage(error);
+    raise TTransportExceptionUnknown.Create(sMsg);
+  end;
 
   // end request and start receiving
-  if not http.FlushAndReceiveResponse
-  then raise TTransportExceptionInterrupted.Create('flush/receive error '+IntToStr(GetLastError));
+  if not http.FlushAndReceiveResponse then begin
+    error := Cardinal( GetLastError);
+    sMsg  := 'WinHTTP recv error '+IntToStr(Int64(error))+' '+WinHttpSysErrorMessage(error);
+    if error = ERROR_WINHTTP_TIMEOUT
+    then raise TTransportExceptionTimedOut.Create( sMsg)
+    else raise TTransportExceptionInterrupted.Create( sMsg);
+  end;
 
   FInputStream := THTTPResponseStream.Create(http);
 end;