问题
In Delphi Tokyo 10.2.x a ESOAPHTTPException
was an Exception descendant with a StatusCode property set in the creator:
ESOAPHTTPException = class(Exception)
private
FStatusCode: Integer;
public
{$IF CompilerVersion <= 15.0}
constructor Create(const Msg: string; SCode: Integer = 0);
{$ELSE}
constructor Create(const Msg: string; SCode: Integer = 0; Dummy: Integer = 0);
{$IFEND}
constructor CreateFmt(const Msg: string; const Args: array of const; SCode: Integer = 0; Dummy: Integer = 0);
property StatusCode: Integer read FStatusCode write FStatusCode;
end;
I could detect specific errors by looking at the StatusCode value:
// WinINet error codes https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.serviceerror%28v=exchg.80%29.aspx
if (E is ESOAPHTTPException) and (ESOAPHTTPException(E).StatusCode = ERROR_INTERNET_TIMEOUT) then
begin
We use THTTPReqResp
. In Tokyo THTTPReqResp
error handling code called HandleWinInetError(GetLastError,
, which tested for some specific errors and for the others called THTTPReqResp.RaiseCheck
, which then called raise ESOAPHTTPException.CreateFmt('
- all passing the GetLastError value. That's how it ended up in the StatusCode property.
But now in Delphi Rio 10.3.1 ESOAPHTTPException = ENetException;
and ENetException = class(Exception);
and there no longer is a StatusCode.
HandleWinInetError
is gone.
Looking though THTTPReqResp
or THTTPReqRespHelper = class helper for THTTPReqResp
I see that e.g. the THTTPReqResp.Execute
raises the ESOAPHTTPException
:
on Ex: ESOAPHTTPException do
begin
if not CanRetry or not IsErrorStatusCode(HTTPResponse.StatusCode) then
raise;
...
end;
... but at that moment HTTPResponse.StatusCode
gets lost (HTTPResponse
is a local var in the method).
Other than hacking the Delphi code to intercept this value (e.g. by 're-creating' a ESOAPHTTPException descendant like in Delphi Tokyo),
does anyone see another way to detect specific errors (in my case the ERROR_INTERNET_TIMEOUT
)?
Did I overlook something?
来源:https://stackoverflow.com/questions/56836189/how-to-detect-specific-timeout-errors-for-thttpreqresp-soap-requests