catch error 400 lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Nicole · 2025-07-10 14:55 Here is a nice site, which gives me free news. It is not nice any more, if I key in anything, which is not found. Then there pops up 2 times "error 400". This is rather annoying to click away and I would prefer it return a silent "nothing found" instead. I am not familiar where I hop on an catch those replies and where exactly to hook in. Can you give me a hint please? The function reads (the last line is formatting 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 // 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    Response := HttpClient.Get(URL);    JsonResponse := GetJSON(Response);    Ersetze.JsonWirdDatei(JsonResponse, 'myNews_json');  // ich speichere es einmal ab    result:=JsonResponse.FormatJSON([]);     result:=VerarbeiteArtikel(result); //VerarbeiteAntwort(result);  finally    HttpClient.Free;  end;end; ---------------------------------------------------------------------- paweld · 2025-07-10 15:12 Use try..except block.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);    except       on E: EHttpClient do      begin        case HttpClient.ResponseStatusCode of          401: Caption := 'Unauthorised';          404: Caption := 'Not found';        else            Caption := Format('error: %d', [HttpClient.ResponseStatusCode]);        end;      end;    end;    JsonResponse := GetJSON(Response);    Ersetze.JsonWirdDatei(JsonResponse, 'myNews_json');  // ich speichere es einmal ab    result:=JsonResponse.FormatJSON([]);     result:=VerarbeiteArtikel(result); //VerarbeiteAntwort(result);  finally    HttpClient.Free;  end;end; ---------------------------------------------------------------------- Nicole · 2025-07-10 16:44 Thank you, looks good, but does not work yet. I read "u_news.pas(218,16) Error: Identifier not found "Caption"" at 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  case HttpClient.ResponseStatusCode of          401: Caption := 'Unauthorised'; If I change caption to result, the error message comes back 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 [Window Title]Fehler [Content]Projekt project_Tiger hat Exception-Klasse »External: ACCESS VIOLATION« ausgelöst mit der Meldung:Access violation reading from address $0000000000000000.  Bei Adresse 10011AEC3 [Ok] followed by an access-thing because it is not json any more. ---------------------------------------------------------------------- paweld · 2025-07-10 18:42 You only showed one function, so I thought TNews was a Form and I wanted to display message on its title. If it is a class then instead of to Caption you can assign this message as a function result or to some property storing the last error etc.