a WEBSERVICE call in a loop, illegalArgumentException error

In this function below I am trying to fetch exchnage rates from a central bank website, which will give you an XML page for each date you request, and since weekends and public holidays are without exchange rates I have to go one day prior to that and try again until I get an exchange rate. The initially entered date is also to be taken a day back, so I do that in the beginning with “tarih=tarih-1”.

This function works the way I want but occasionally gives me this error:

Type: com.sun.star.lang.IllegalArgumentException

…for this line:

xml_string = svc.callFunction("WEBSERVICE", array(mbpage))

for instance if the date entered is 01.02.2021 (i.e. first of February).

Any help appreciated.

function kur(tarih as date, parabirimi as string) as currency

on error goto hata

dim svc as object
dim mbpage as string
dim counter as integer 


svc = createUnoService( "com.sun.star.sheet.FunctionAccess" )


mbpage = "http://www.tcmb.gov.tr/kurlar/" & year(tarih) & format(month(tarih),"0#") & "/" & format(day(tarih),"0#") & format(month(tarih),"0#") & year(tarih) & ".xml"

xml_string = svc.callFunction("WEBSERVICE", array(mbpage))

kur() = svc.callFunction("FILTERXML", array(xml_string, "number(/Tarih_Date/Currency[@CurrencyCode='"+ucase(parabirimi)+"']/ForexBuying)"))

exit function


if (counter > 5) then
	exit function
end if

goto top

end function

I solved the problem by splitting the function in two, having one as an outer wrap for the main function, calling the latter in a loop