2
0
Эх сурвалжийг харах

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 сар өмнө
parent
commit
aa182cb147

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

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