Browse Source

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.

Yuri Serebrennikov 3 months ago
parent
commit
aa182cb147
1 changed files with 15 additions and 2 deletions
  1. 15 2
      packages/fcl-web/src/base/fphttpclient.pp

+ 15 - 2
packages/fcl-web/src/base/fphttpclient.pp

@@ -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.