The EHTTPClient class now implements an overloaded constructor that accepts both an error message and an associated HTTP status code, enabling retrieval of the HTTP error code when an exception occurs.

This commit is contained in:
Yuri Serebrennikov 2025-05-13 02:04:51 +03:00
parent 37a7474471
commit aa182cb147

View File

@ -424,7 +424,11 @@ Type
end;
EHTTPClient = Class(EHTTP);
EHTTPClient = Class(EHTTP)
public
constructor Create(const AStatusText: String; AStatusCode: Integer); overload;
end;
// client socket exceptions
EHTTPClientSocket = class(EHTTPClient);
// reading from socket
@ -1351,7 +1355,7 @@ begin
if not Result then
Exit;
if not CheckResponseCode(FResponseStatusCode,AllowedResponseCodes) then
Raise EHTTPClient.CreateFmt(SErrUnexpectedResponse,[ResponseStatusCode]);
Raise EHTTPClient.Create(SErrUnexpectedResponse, ResponseStatusCode);
if HeadersOnly Or (AllowRedirect and IsRedirect(FResponseStatusCode)) then
exit;
if CompareText(CheckTransferEncoding,'chunked')=0 then
@ -2503,5 +2507,14 @@ begin
end;
end;
{ EHTTPClient }
constructor EHTTPClient.Create(const AStatusText: String; AStatusCode: Integer);
begin
inherited CreateFmt(AStatusText, [AStatusCode]);
StatusText := AStatusText;
StatusCode := AStatusCode;
end;
end.