在 Delphi Tokyo 10.2.xaESOAPHTTPException
中是一个 Exception 后代,在创建者中设置了 StatusCode 属性:
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;
我可以通过查看 StatusCode 值来检测特定错误:
// 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
我们使用THTTPReqResp
. 在 Tokyo的THTTPReqResp
错误处理代码中调用HandleWinInetError(GetLastError,
,它测试了一些特定的错误,而其他的称为THTTPReqResp.RaiseCheck
,然后调用raise ESOAPHTTPException.CreateFmt('
- 都传递了 GetLastError 值。这就是它最终出现在 StatusCode 属性中的方式。
但现在在 Delphi Rio 10.3.1 中ESOAPHTTPException = ENetException;
,ENetException = class(Exception);
不再有 StatusCode。
HandleWinInetError
离开了。
看,THTTPReqResp
或者THTTPReqRespHelper = class helper for THTTPReqResp
我看到,例如THTTPReqResp.Execute
引发ESOAPHTTPException
:
on Ex: ESOAPHTTPException do
begin
if not CanRetry or not IsErrorStatusCode(HTTPResponse.StatusCode) then
raise;
...
end;
...但在那一刻HTTPResponse.StatusCode
迷失了(HTTPResponse
是方法中的本地变量)。
除了破解 Delphi 代码来拦截这个值(例如,通过像 Delphi Tokyo 那样“重新创建”一个 ESOAPHTTPException 后代),有没有人看到另一种检测特定错误的方法(在我的例子中ERROR_INTERNET_TIMEOUT
)?我忽略了什么吗?