[Pas2js] page reload when server restarted not 100% reliable
Luca Olivetti
luca at ventoso.org
Tue Sep 23 09:13:00 CEST 2025
El 22/9/25 a les 18:44, Luca Olivetti via Pas2js ha escrit:
> El 22/9/25 a les 18:33, Michael Van Canneyt ha escrit:
>
>>> I'd like the exception to be propagated to the outer code so my
>>> try..catch would work.
>>
>> Did you try putting the above in the load ?
>>
>> window.addEventListener("load", function () {
>> if (typeof rtl === 'undefined' || typeof QRCode === 'undefined') {
>> console.log('rtl o QRCode no definidos, recargo pagina');
>> setTimeout(function() { location.reload(); }, 5000);
>> } else {
>> try {
>> rtl.run();
>> } catch(err) {
>> console.log('error '+err.message+', recargo pagina');
>> setTimeout(function() { location.reload(); }, 5000);
>> }
>> }
>> });
>
> Again, I'm not 100% sure but I think I tried everything at the time.
> In any case in the scenario I described It shouldn't make a difference:
> something is showing the exception instead of being propagated to my
> try..catch block.
>
The "trick" is to catch the exception inside the pas2js application,
since TBrowserApplication.OnException doesn't handle the exception, I
had to override the ShowException method.
procedure TMyApplication.ShowException(E: Exception);
Var
S : String;
T : TTimer;
begin
if (E<>nil) then
S:=E.ClassName+': '+E.Message
else if ExceptObjectJS then
S:=TJSObject(ExceptObjectJS).toString;
S:='Unhandled exception caught: '+S;
Console.Log(s);
//ha llegado a inicializar
if Assigned(errorScreen) then
showErrorScreen(S);
T:=TTimer.Create(nil);
T.Interval:=5000;
T.OnTimer:=@reconnect;
T.Enabled:=true;
end;
Now I'll have to decide if I still have to check for rtl === 'undefined'
Bye
--
Luca
More information about the Pas2js
mailing list