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):
// sucht zu einem Ticker die Nachrichten
function 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;