From ab38ec3c50a3cbbfb2a975b68845d4cbb890aba3 Mon Sep 17 00:00:00 2001 From: inoussa Date: Thu, 8 May 2014 14:15:38 +0000 Subject: [PATCH] Better transport error reporting : ETransportExecption.ExtendedErrorInfo (Thanks to Michael Van Canneyt) git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3023 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- wst/trunk/base_service_intf.pas | 9 ++++++++- wst/trunk/synapse_http_protocol.pas | 23 +++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/wst/trunk/base_service_intf.pas b/wst/trunk/base_service_intf.pas index 26277cccf..2493a2575 100644 --- a/wst/trunk/base_service_intf.pas +++ b/wst/trunk/base_service_intf.pas @@ -65,7 +65,14 @@ type EServiceException = class(Exception) end; EServiceExtensionException = class(Exception) end; - ETransportExecption = class(EServiceException) end; + + ETransportExecption = class(EServiceException) + private + FExtendedErrorInfo : string; + public + property ExtendedErrorInfo : string + read FExtendedErrorInfo write FExtendedErrorInfo; + end; EBaseRemoteException = class(EServiceException) private diff --git a/wst/trunk/synapse_http_protocol.pas b/wst/trunk/synapse_http_protocol.pas index 64f7eefdb..30e9cdb69 100644 --- a/wst/trunk/synapse_http_protocol.pas +++ b/wst/trunk/synapse_http_protocol.pas @@ -203,11 +203,30 @@ begin end; procedure THTTPTransport.DoSendAndReceive(ARequest, AResponse : TStream); +var + s, s2 : string; + ans : AnsiString; + e : ETransportExecption; begin FConnection.Document.Clear(); FConnection.Document.CopyFrom(ARequest,0); - if not FConnection.HTTPMethod('POST',FAddress) then - raise ETransportExecption.CreateFmt(SERR_FailedTransportRequest,[sTRANSPORT_NAME,FAddress]); + if not FConnection.HTTPMethod('POST',FAddress) then begin + s := sysutils.Format(SERR_FailedTransportRequest,[sTRANSPORT_NAME,FAddress]); + s := s+sysutils.Format('Result code: %d, message: "%s"',[FConnection.ResultCode,Fconnection.ResultString]); + s2 := ''; + if (FConnection.Document.Size > 0) then begin + SetLength(ans,FConnection.Document.Size); + Move(FConnection.Document.Memory^,ans[1],FConnection.Document.Size); + try + s2 := ans; + except + s2 := ''; + end; + end; + e := ETransportExecption.Create(s); + e.ExtendedErrorInfo := s2; + raise e; + end; AResponse.CopyFrom(FConnection.Document,0); FConnection.Document.Clear(); end;