[solved] How to catch error 400 ? lazarus / 21-General ---------------------------------------------------------------------- Nicole · 2025-07-17 20:24 Within a nicely running code, there is a problem with this line: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     try    Response := HttpClient.Get(URL);      The problem is: I can "try", but the error message is dropped and my except block never reached. The error message, which is dropped with or without "try" reads,               [Debuggerausnahmen-Nachricht] Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i [Break]Projekt project_xxx hat Exception-Klasse »EHTTPClient« ausgelöst mit der Meldung:Unexpected response status code: 400 Bei Adresse 1004B1065[Diesen Ausnahmetyp übergehen][Continue] What can I do that the error-message is NOT shown to the user but passed on to my except block below? Thank you all for that!! ---------------------------------------------------------------------- paule32 · 2025-07-17 20:44 short Question => did you .CREATE ? short Answer: - you can not simply use TRY on Get Information's from a WebSite. - you have to drop a AJAX Request (GET / POST) - then you can handle the Request with the Result after getting Response of the Request - this can be done by IF THEN ELSE or CASE Statement - but not simply per TRY - except, you use a Framework that supports Exception's ---------------------------------------------------------------------- dbannon · 2025-07-17 23:52 Is your issue related to the two things we expect from a 'try' ?  Handle the exception AND ensure resources are released. This works OK, its a copy and paste from my project with some unnecessary things stripped out for clarity  - Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TMistySync.Downloader(    URL : string; out SomeString : String;) : boolean;var    Client: TFPHTTPClient;begin    if DebugMode then debugln('TMistySync.Downloader URL is ' + URL);     Client := TFPHttpClient.Create(nil);    Client.AddHeader('User- Agent','Mozilla/5.0 (compatible; fpweb)');    Client.AddHeader('Content-Type','application/HTML; charset=UTF-8');  Client.AllowRedirect := true;    Client.ConnectTimeout := 8000;      // mS ?  was 3000, I find initial response from github very slow ....    Client.IOTimeout := 4000;           // mS ? was 0    SomeString := '';    try        try            SomeString := Client.Get(URL);        except            on E: EHTTPClient do begin                                        // eg, File Not Found, we have asked for an unavailable file                ErrorString := 'TMistySync.Downloader - EHTTPClient Error ' + E.Message                  + ' ResultCode ' + inttostr(Client.ResponseStatusCode);              exit(SayDebugSafe(ErrorString));            end;            on E: ESocketError do begin                ErrorString := 'TMistySync.Downloader - SocketError ' + E.Message     // eg failed dns, timeout etc                    + ' ResultCode ' + inttostr(Client.ResponseStatusCode);                SomeString := 'Fatal, is server available ?';                exit(SayDebugSafe(ErrorString));                end;            on E: EInOutError do begin                ErrorString := 'TMistySync Downloader - InOutError ' + E.Message;                // might generate "TGithubSync Downloader - InOutError Could not initialize OpenSSL library"                SomeString := 'Failed to initialise OpenSSL';           // is error message translated ?                exit(SayDebugSafe(ErrorString));                end;            on E: ESSL do begin                ErrorString := 'TMistySync.Downloader - SSLError ' + E.Message;         // eg openssl problem, maybe FPC cannot work with libopenssl                SomeString := 'Failed to work with OpenSSL';                exit(SayDebugSafe(ErrorString));              end;            on E: Exception do begin                ErrorString := 'TMistySync.Downloader Unexpected Exception ' + E.Message + ' downloading ' + URL;                ErrorString := ErrorString + ' HTTPS error no ' + inttostr(Client.ResponseStatusCode);                exit(SayDebugSafe(ErrorString));                end;        end;      Result := Client.ResponseStatusCode = 200;        // My version of this in GitHubSync then did some processing of Client.ResponseHeaders, apparently not necessary here.    finally        Client.Free;    end;end;              Davo ---------------------------------------------------------------------- Nicole · 2025-07-18 09:00 Thank you for the answers. Yes, I posted it already. At the moment I am not sure, what to change. Here is my full method. Be aware it is a work-in-progress-version and has a lot of issues yet. The first line after try try is it, which drops the error message. The debugging line below "ShowMessage(Response);" is not seen in case of server-error 400. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // sucht zu einem Ticker die Nachrichtenfunction TNews.Suche_NewsZu(Ticker: string; abDatum, bisDatum: TDate): string;var URL, Response: string;  HttpClient: TFPHTTPClient;    JsonResponse: TJSONData;    ts_ab, ts_bis: Int64;    s_from, s_to: string;begin  Result := '';   ts_ab := DateTimeToUnix(abDatum);  ts_bis := DateTimeToUnix(bisDatum + 1);  // period2 ist exklusiv!   s_from := IntToStr(ts_ab);  s_to := IntToStr(ts_bis);  // brauche ich offenbar nicht, kam von Yahoo- Vorlage   URL := 'https://newsapi.org/v2/everything?q=' + Ticker +  '&from=' + s_from + '&sortBy=publishedAt&apiKey='+ APIKEY_News;   HttpClient := TFPHTTPClient.Create(nil);  HttpClient.AddHeader('User- Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36');  try    try    Response := HttpClient.Get(URL);      ShowMessage(Response);    except      on E: EHttpClient do      begin        case HttpClient.ResponseStatusCode of          401: result := 'Unauthorised';          404: result := 'Not found';          else        //  result := Format('error: %d', [HttpClient.ResponseStatusCode]);        end;      end;    end;     JsonResponse := GetJSON(Response);    ShowMessage(JsonResponse);    Ersetze.JsonWirdDatei(JsonResponse, 'myNews_json');  // ich speichere es einmal ab    result:=JsonResponse.FormatJSON([]);     result:=VerarbeiteArtikel(result);  finally    HttpClient.Free;  end;end; ---------------------------------------------------------------------- dseligo · 2025-07-18 10:16 Quote from: Nicole on July 18, 2025, 11:00:23 amThe debugging line below "ShowMessage(Response);" is not seen in case of server-error 400. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i       on E: EHttpClient do      begin        case HttpClient.ResponseStatusCode of          401: result := 'Unauthorised';          404: result := 'Not found';          else          //  result := Format('error: %d', [HttpClient.ResponseStatusCode]);        end;      end;  In you 'case' code you don't have 400 and in 'else' part code is commented out. ---------------------------------------------------------------------- Nicole · 2025-07-18 13:49 @Dseligo this is what I meant by "work in progress version". This misses the point, that I see an error message before I have the chance to do anything in the exception block. In other words: "try try" does not work as expected. Therefore I originally did not post the lines which follows "try try". They are not even reached. ---------------------------------------------------------------------- rvk · 2025-07-18 14:07 Quote from: Nicole on July 18, 2025, 03:49:02 pmIn other words: "try try" does not work as expected. Therefore I originally did not post the lines which follows "try try". They are not even reached. It does work as expected. Just not what you expected (because you didn't know how exception are handled) You have this.... the first try matches a finally. So that finally is always executed... as expected... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i try    try      Response := HttpClient.Get(URL);      ShowMessage(Response);    except      on E: EHttpClient do      begin        case HttpClient.ResponseStatusCode of          401: result := 'Unauthorised';          404: result := 'Not found';          else        //  result := Format('error: %d', [HttpClient.ResponseStatusCode]);        end;      end;      // JUMPS OUT OF THE COMPLETE PROCEDURE (unless there is an overruling try/finally)    end;     // THIS ONLY GETS EXECUTED IF NOT EXCEPT    JsonResponse := GetJSON(Response);    ShowMessage(JsonResponse);    Ersetze.JsonWirdDatei(JsonResponse, 'myNews_json');  // ich speichere es einmal ab    result:=JsonResponse.FormatJSON([]);     result:=VerarbeiteArtikel(result);  finally    // EXCEPT JUMPS HERE  HttpClient.Free;  end; But you need to realize that once you get inside an exception part.... everything after that except is not executed. After the except part, the code jumps to the exit (in this case the finally is still executed because that's in a first try overruling). So if you want a showmessage inside the except... you'll need to put it insude the except or in the finally (I would suggest the except). The problem is that there is a GetJSON(Response) call before the Showmessage. Does Response contain correct json? ---------------------------------------------------------------------- Warfley · 2025-07-18 14:15 Quote from: Nicole on July 17, 2025, 10:24:59 pm     [Debuggerausnahmen-Nachricht] Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i [Break]Projekt project_xxx hat Exception-Klasse »EHTTPClient« ausgelöst mit der Meldung:Unexpected response status code: 400 Bei Adresse 1004B1065[Diesen Ausnahmetyp übergehen][Continue] What can I do that the error-message is NOT shown to the user but passed on to my except block below? Thats lazarus, not your program, try running the program without the debugger and see if the same message appears ---------------------------------------------------------------------- Nicole · 2025-07-18 14:24 @rvk you miss the point, that I do not even get there @Warfley This is true! Thank you. As my software is work in progress I start is usually within the debugger. Is there an option to say Lazarus, not to drop the error message at this point? Or a compiler directive for just this line? ---------------------------------------------------------------------- rvk · 2025-07-18 14:27 Quote from: Nicole on July 18, 2025, 04:24:46 pm@rvk you miss the point, that I do not even get there You don't get there because there was an exception. An exception ALWAYS jumps strait out of the routine directly after the except clause is done. Your Showmessage is below that except begin/end so never gets executed when there is an exception. Please read the commented and highlighted lines in my example. See below... ---------------------------------------------------------------------- af0815 · 2025-07-18 15:52 Quote from: Nicole on July 18, 2025, 04:24:46 pmIs there an option to say Lazarus, not to drop the error message at this point? Maybe go into "Options for Project xx" there in Project options, Language Exceptions and enter there "EHTTPClient". But this suppress all stops from this exception. ---------------------------------------------------------------------- rvk · 2025-07-18 16:00 Oops. I was wrong. It will execute after except. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i begin  try    try      raise Exception.Create('a');      Showmessage('a');    except      Showmessage('b');    end;    Showmessage('c'); // will execute on except  finally    Showmessage('d');  end;end; So the showmessage should have been shown. BUT... you have a line JsonResponse := GetJSON(Response); just above that ShowMessage. What does Response contain???? Does it contain correct json after a code 400? ---------------------------------------------------------------------- Nicole · 2025-07-21 09:18 @rvk thank you for your answer. However, I do not understand it. Please be aware, that I do not work much with servers and usually not with exceptions They "never" fix what I want to fix. So dummy question: Where shall I write the url-get line, which drops the exception? (fulll code posting above) ---------------------------------------------------------------------- rvk · 2025-07-21 09:59 Quote from: Nicole on July 21, 2025, 11:18:01 amSo dummy question: Where shall I write the url-get line, which drops the exception? (fulll code posting above) Consider this (your) code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     try    Response := HttpClient.Get(URL);      ShowMessage(Response);    except      on E: EHttpClient do      begin        case HttpClient.ResponseStatusCode of          401: result := 'Unauthorised';          404: result := 'Not found';          else        //  result := Format('error: %d', [HttpClient.ResponseStatusCode]);        end;      end;    end;     // WHAT IS THE VALUE OF RESPONSE HERE ????     JsonResponse := GetJSON(Response);    ShowMessage(JsonResponse);    Ersetze.JsonWirdDatei(JsonResponse, 'myNews_json');  // ich speichere es einmal ab    result:=JsonResponse.FormatJSON([]);What is the value of Response on lines 16/17 (highlighted)??? Because you get an exception in line 2, you can't be sure of what the content of Response is !!! In line 17 you have a line GetJSON(Response). But are you sure Response contains "correct" json ??? I'm sure it doesn't... so you probably get a second exception. One options is that you can move the handling of a correct Response inside the try. Like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     try    Response := HttpClient.Get(URL);      JsonResponse := GetJSON(Response);      ShowMessage(JsonResponse);      Ersetze.JsonWirdDatei(JsonResponse, 'myNews_json');  // ich speichere es einmal ab      result:=JsonResponse.FormatJSON([]);      result:=VerarbeiteArtikel(result);    except      on E: EHttpClient do      begin        case HttpClient.ResponseStatusCode of          401: result := 'Unauthorised';          404: result := 'Not found';        else          //  result := Format('error: %d', [HttpClient.ResponseStatusCode]);        end;      end;    end; Another option is to only process the Response if result isn't filled in by the case in the except. Like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     try    Response := HttpClient.Get(URL);      ShowMessage(Response);    except      on E: EHttpClient do      begin        case HttpClient.ResponseStatusCode of          401: result := 'Unauthorised';          404: result := 'Not found';          else        //  result := Format('error: %d', [HttpClient.ResponseStatusCode]);        end;      end;    end;     if result = '' then // no errors found    begin      JsonResponse := GetJSON(Response);      ShowMessage(JsonResponse);      Ersetze.JsonWirdDatei(JsonResponse, 'myNews_json');  // ich speichere es einmal ab      result:=JsonResponse.FormatJSON([]);      result:=VerarbeiteArtikel(result);    end; At least that way... the Response only gets processed when there is no error on the page (401 or 404). ---------------------------------------------------------------------- Nicole · 2025-07-21 12:54 Thank you for trying. Unfortunately all this is too late: "Response := HttpClient.Get(URL);" triggers the exception although written after the try. This is due to the Lazarus debugger, not to the compiled software. As I usually run my software from the debugger, I keep clicking away error messages. In this very case every time I search for a unknown word, which has no entry on a site, it is triggered. Annoying. in other words: The answer of AF (above, very small paragraph) may be a workaround. I am not sure, if I want to try it, because I do not understand what this may mean to my debugging. ---------------------------------------------------------------------- af0815 · 2025-07-21 13:06 Quote from: Nicole on July 21, 2025, 02:54:42 pmin other words: The answer of AF (above, very small paragraph) may be a workaround. I am not sure, if I want to try it, because I do not understand what this may mean to my debugging. You can focus on your exceptionhandling. Becaus it supess not the exception handling itself, it supress only an unwanted stop of the ide, not more or less. And you can easy change the behavior. ---------------------------------------------------------------------- rvk · 2025-07-21 13:45 Quote from: Nicole on July 21, 2025, 02:54:42 pmThank you for trying. Unfortunately all this is too late: "Response := HttpClient.Get(URL);" triggers the exception although written after the try.This has already been explained. This triggers an exception dialog from the debugger, not from your program. If you press continue it all works fine. You can suppress the debugger exception handler by adding that exception to the ignore exception list for the debugger. Look back in this topic. It's explained in this post: Quote from: af0815 on July 18, 2025, 05:52:09 pmQuote from: Nicole on July 18, 2025, 04:24:46 pmIs there an option to say Lazarus, not to drop the error message at this point? Maybe go into "Options for Project xx" there in Project options, Language Exceptions and enter there "EHTTPClient". But this suppress all stops from this exception. ---------------------------------------------------------------------- rvk · 2025-07-21 13:52 BTW. If you really don't want exception handling in TFPHTTPClient then you can use HTTPMethod and pass the codes you want to avoid the exceptions. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     Procedure HTTPMethod(Const AMethod,AURL : String; Stream : TStream; Const AllowedResponseCodes : Array of Integer); virtual; So doing this should avoid any exeption: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i HttpClient.Get('GET', URL, Response, [200, 401, 404]); You still need to check the ResponseStatusCode for correct result but now there will be no exception for those return codes. ---------------------------------------------------------------------- paule32 · 2025-07-21 16:12 I thinking that what Nicole is tried so far is a blocking Web Socket. I would bet when she use the Indy Components which are available under Lazarus and FPC by Remy, then she can use Events like OnAfterConnect (e.g.) or OnResponseError (e.g.). I don't know the Details anymore since I have broke my Development's on the Delphi Line ... But you/she will be come a Friend of TCPClient and TCPServer and many more like AntiFreeze Component. Because the Indy Components are non-blocking and can handle more than one Request at same Time ... ---------------------------------------------------------------------- Nicole · 2025-07-21 16:29 No, I have not installed Indy. I use fphttpclient, fpjson, jsonparser, ---------------------------------------------------------------------- rvk · 2025-07-21 16:32 Quote from: Nicole on July 21, 2025, 06:29:03 pmI use fphttpclient, fpjson, jsonparser, Just read my two posts above and say what you don't understand (if it doesn't work for you). ---------------------------------------------------------------------- Nicole · 2025-07-23 08:50 Indy is not installed and I want to avoid it. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i interfaceuses classes, sysutils, strutils,dialogs, fphttpclient, fpjson, jsonparser,     dateutils, types, Unit_myStringList; Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  ....HttpClient.Get('GET', URL, Response, [400, 200, 401, 404]);  .....  the compiler says Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i u_news.pas(231,63) Error: Wrong number of parameters specified for call to "Get" ---------------------------------------------------------------------- rvk · 2025-07-23 08:53 Quote from: Nicole on July 23, 2025, 10:50:56 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i interfaceuses classes, sysutils, strutils,dialogs, fphttpclient, fpjson, jsonparser,     dateutils, types, Unit_myStringList; Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  ....HttpClient.Get('GET', URL, Response, [400, 200, 401, 404]);  .....  the compiler says Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i u_news.pas(231,63) Error: Wrong number of parameters specified for call to "Get"Sorry, I did say .Get but I meant HTTPMethod. (as stated in the declaration above it) So it's Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i HttpClient.HTTPMethod('GET', URL, Response, [400, 200, 401, 404]); ---------------------------------------------------------------------- Nicole · 2025-07-26 11:15 Now, I know, why I do not get any answer. My last comment was lost. I was a compiler-error message, saying similar to: "count of arguments is not correct". This means, that I must not write "HttpClient.Get('GET', URL, Response, [400, 200, 401, 404]); " the array is one parameter too many, - thinks the compiler. In the meanwhile I found in one of the documentations a hint, what error 400 means, this was alike "strange thing what you send". On study more of it, I could solve in two cases the source of the problem by adding a different header to my request. The other ones are still unresolved. So anybody either has an idea how to change the get-line or I tend to search for a different API-service. ---------------------------------------------------------------------- Thaddy · 2025-07-26 12:33 The only documentation you need is how http errors are defined. https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status That makes the discussion a LOT easier. Even better, stick to: https://www.iana.org/assignments/http-status-codes/http-status- codes.xhtml Problem solved. ---------------------------------------------------------------------- rvk · 2025-07-26 15:46 Quote from: Nicole on July 26, 2025, 01:15:54 pmNow, I know, why I do not get any answer. My last comment was lost. I was a compiler-error message, saying similar to: "count of arguments is not correct". This means, that I must not write "HttpClient.Get('GET', URL, Response, [400, 200, 401, 404]); " the array is one parameter too many, - thinks the compiler. Did you read my last post where I corrected this. https://forum.lazarus.freepascal.org/index.php?topic=71791.msg561407#m sg561407 So, don't use .Get() but use .HTTPMethod. ---------------------------------------------------------------------- Nicole · 2025-07-26 17:17 @rvk I worked all day. Maybe I miss the very first point. Somehow I am not able to bring it to run. I make you a screenshot. I need a string as result. And it shall be the same string kind, I spent some hours to formate for my RichMemo. Why is my TStream declaration not taken? How to make a string from it? Forgive m, if it is something obvious. I cannot see it. @Thaddy thank you for the useful links. They help me, but unfortunately not with the problem I try to solve today I cannot make those server replies VISIBLE in the sense of catchable by running the app called from within the IDE. The error messages are dropped after the try try, pls see above for the code. As I usually start my app from the IDE, this really is annoying. ---------------------------------------------------------------------- rvk · 2025-07-26 17:43 Quote from: Nicole on July 26, 2025, 07:17:41 pmWhy is my TStream declaration not taken? How to make a string from it? Two problems with your code. 1) You never use TStream directly. This is just a base class from which other streams are derived. Like TStringStream, TFileStream and TMemoryStream etc. The var declaration can be TStream (because that's just a pointer) but you need to create a stream class like mentioned above. 2) In your code you need to create the stream which will hold your data. You didn't do that. You can look at the Get() function itself to see how it's done. That looks like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TFPCustomHTTPClient.Get(const AURL: string): rawbytestring;var  SS: TRawByteStringStream;begin  SS := TRawByteStringStream.Create;  try  Get(AURL, SS);    Result := SS.Datastring;  finally    SS.Free;  end;end; So in your code you need to do something like this (just typed out of hand so I didn't tested this for typos): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  AntwortStream: TRawByteStringStream;  HttpClient: TFPHttpClient;begin  HttpClient := TFPHttpClient.Create(nil);  AntwortStream := TRawByteStringStream.Create;  try     HttpClient.AddHeader('user- agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)');    HttpClient.HTTPMethod('GET', URL, AntwortStream, [400, 200, 401, 404, 426]);     Response := AntwortStream.DataString;     // you also need to check HttpClient.ResponseStatusCode because if it's 400+ then you might not have a valid JSON   finally    AntwortStream.Free;    HttpClient.Free;  end; You also need to check HttpClient.ResponseStatusCode because if it's 400+ then you might not have a valid JSON. You can check what's in the Response string but it you got another code than 200, it might not contain valid JSON. You don't get an exception but you can show the ResponseStatusCode to the user via a Showmessage. ---------------------------------------------------------------------- Nicole · 2025-07-26 18:16 I see an error-message!! Many would be surprised how happy I am about! Thank you so much. it reads Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i $000000000EE180B8^: '{"status":"error","code":"parameterInvalid","message":"You are trying to request results too far in the past. Your plan permits you to request articles as far back as 2025-06-25, but you have requested 2025-01-27. You may need to upgrade to a paid plan."}' So there are a lot more questions now: 1) How to grab, that is is an error? In other words: how to address this very status-answer. 2) How to extract the helpful information, ""You are trying to request results too far...." 3) If the status is "ok" instead, how to fit, that it works with this follow-up lines (result: string): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i //  Response := HttpClient.Get(URL);  // ich lese hier sehr häufig "Fehler 400", rufe ich dasselbe Link via Browser auf, dann geht es.  // JsonResponse := GetJSON(Response);  result:=JsonResponse.FormatJSON([]);   if result <> '' then result:=VerarbeiteArtikel(result)                  else Result:='keine Nachrichten gefunden'; Probably you wrote it already, however I am not sure, which belongs to what. ---------------------------------------------------------------------- rvk · 2025-07-26 19:28 Quote from: Nicole on July 26, 2025, 08:16:11 pm1) How to grab, that is is an error? In other words: how to address this very status-answer.If the HttpClient.ResponseStatusCode is 200 you have a valid response. You can check if HttpClient.ResponseHeaders['content-type'] contains the word json to make sure the result in response is actual a json string. But if the code is 200 and you expect json you probably got json back. If the HttpClient.ResponseStatusCode is 400+ you have an error. Here you can also check the HttpClient.ResponseHeaders['content-type'] for the word json but seeing the response you gave it's probably also always json. Quote from: Nicole on July 26, 2025, 08:16:11 pm2) How to extract the helpful information, ""You are trying to request results too far...."So... Next is to interpret that json and extract you're information. For the 200 you should know what the json contains. For the 400+ result json it seems to have a status and message field. If the status field is 'error' (and not 'success' or 'ok' or something) then you can just show the message value as error. Quote from: Nicole on July 26, 2025, 08:16:11 pm3) If the status is "ok" instead, how to fit, that it works with this follow-up lines (result: string): Yeah... If the status is 'ok' you have more information in the json. That's the information you requested. I don't know how it looks but you just need to process the json and show the values to the user. ---------------------------------------------------------------------- Nicole · 2025-07-28 15:39 Thank you for your answer. Can you pls. check the first text-pasting of above? This was the answer of the server. As I knew, he would not like it, I asked it to give me data for one year back. He writes the error-message-text, you see in the pasted string. What I do not know how to do: How to bring this very text into a string (to show it to the user later)? In other words, the answer is " '{"status":"error","code":"parameterInvalid","message":"You are trying to request results too f" and I want to save the element message into a string. I would need anything which looks familiar to me. Just as: mystring_result:=myhtml_response.message.text; // gives the reason for the trouble or myBoolean:=myAnwerfromtheWeb.status;  // gives "error" or "ok" ---------------------------------------------------------------------- dseligo · 2025-07-28 16:10 Quote from: Nicole on July 28, 2025, 05:39:54 pmIn other words, the answer is " '{"status":"error","code":"parameterInvalid","message":"You are trying to request results too f" This looks like JSON (but it's missing final } bracket). Try with something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses fpjson;...var JSONData: TJSONData;...try  JSONData := GetJSON(myhtml_response);  try    try      WriteLn(JSONData.GetPath('status').AsString);      WriteLn(JSONData.GetPath('code').AsString);      WriteLn(JSONData.GetPath('message').AsString);    except      WriteLn('error: path doesn''t exists');    end;  finally    JSONData.Free;  end;except  WriteLn('not JSON');end;