@@ -185,8 +185,8 @@ procedure TALNetHttpClientPool.DoGet(var AExtData: Tobject);
185185 Var LUri := Turi.Create(aUrl);
186186 var LNetHttpClient := ALAcquireKeepAliveNetHttpClient(LUri);
187187 try
188- // in case we cut the connection I already see this returning sucess with
189- // a partial content. What a sheet! !
188+ // In case we lose the connection, this might return success with
189+ // partial content. What a mess !
190190 result := LNetHttpClient.Get(aUrl, LResponseContent);
191191 finally
192192 ALReleaseKeepAliveNetHttpClient(LUri, LNetHttpClient);
@@ -218,6 +218,15 @@ procedure TALNetHttpClientPool.DoGet(var AExtData: Tobject);
218218 if (not assigned(RetrieveCachedData)) or
219219 (not RetrieveCachedData(LNetHttpClientPoolRequest.Url, LHTTPResponse, LResponseContent)) then begin
220220 LHTTPResponse := _HttpGetUrl(LNetHttpClientPoolRequest.Url, LResponseContent);
221+ // Client error responses (400 499)
222+ // Server error responses (500 599)
223+ if (LHTTPResponse = nil ) or
224+ ((LHTTPResponse.StatusCode >= 400 ) and (LHTTPResponse.StatusCode <= 599 )) then begin
225+ if assigned(LNetHttpClientPoolRequest.OnErrorCallBack) then
226+ LNetHttpClientPoolRequest.OnErrorCallBack(' HTTP request failed' , LNetHttpClientPoolRequest.FExtData);
227+ exit;
228+ end ;
229+ ALDecompressHttpResponseContent(LHTTPResponse.ContentEncoding, LResponseContent);
221230 if (assigned(CacheData)) then CacheData(LNetHttpClientPoolRequest.Url, LHTTPResponse, LResponseContent);
222231 end ;
223232 end
@@ -226,9 +235,6 @@ procedure TALNetHttpClientPool.DoGet(var AExtData: Tobject);
226235 else LResponseContent.LoadFromFile(LNetHttpClientPoolRequest.Url);
227236 end ;
228237
229- // decode the result if necessary
230- if (LHTTPResponse <> nil ) then ALDecompressHttpResponseContent(LHTTPResponse.ContentEncoding, LResponseContent);
231-
232238 // fire the OnSuccess
233239 LNetHttpClientPoolRequest.OnSuccessCallBack(LHTTPResponse, LResponseContent, LNetHttpClientPoolRequest.FExtData);
234240
0 commit comments