소스 검색

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 달 전
부모
커밋
aa182cb147
1개의 변경된 파일15개의 추가작업 그리고 2개의 파일을 삭제
  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.