Await and raise an error problem

Hi,

In my web app I have one procedure for handling all errors:

procedure AppException(Sender: TObject; AError: TApplicationError; var Handled:Boolean);
begin
  console.log('I have an error');
end;

And the procedure is attached to onError event when the form is created:

Application.OnError := AppException;

I raise error like below.

ResponseLogin:=Await(dmDataModule.xdtwbclntClient.RawInvokeAsync('IWEBService.LogOn',[wbdtUserName.Text,wbdtUserPassword]));

vToken:=String(TJSObject(ResponseLogin.Result)['value']);
              
if(vToken='')then
  raise Exception.Create('Unknown login');

In browser console I got uncaught promis error

Uncaught (in promise) ObjectFJSError: Error: Unknown login. 
    at Object.Create$1 (http://localhost:8000/dotwpwa/dotwpwa.js:1967:23)
    at Object.c.$create (http://localhost:8000/dotwpwa/dotwpwa.js:328:19)
    at Object.wbtnLoginClick (http://localhost:8000/dotwpwa/dotwpwa.js:35813:42)fMessage: "Unknown login."[[Prototype]]: Object

Why in this case my procedure AppException for handling all errors is not running?

Technical background:

We applied an improvement to have this handled via Application.OnError()

1 Like

Can I ask when do you plan release the new TMS WEB Core which will solve described problem?

We are working on v2.0 right now, aimed for H1 2022. No more precise timeframe at this moment unfortunately.

Hi
I see that in version 2.0 is better with this issue, now the AppException is running if the exception occured but the problem is that AError: TApplicationError is undefined nad I can't get error message.

I cannot see this here. Do you see the red error box at the bottom of the page?
Please provide a sample source app with which a problem can be reproduced.

procedure AppException(Sender: TObject; AError: TApplicationError; var Handled:Boolean);
begin
console.log('I have an error');
end;

and

Application.OnError := AppException;

when I try get error message like this:

AError.AMessage

I get an error

Uncaught TypeError: Cannot read properties of undefined (reading 'toUpperCase')

and in debug mode (dev tools in browser) I see that AError variable is undefined.

I asked if you see the red error box and I asked a sample project, none of which was given. Lost time for you and for us.

Here is my test project and I see no problem here.
Project3.zip (5.3 KB)

The issue topic is "Await and raise an error problem" try do the same with await version.

I asked a sample project.

I think that I described the problem step by step.

Btw ok ... I changed your example project (added await)
awaitcatcherror.zip (1.4 MB)

and when you click "Try this" button you can see in console that we have two error objects (twice AppException procedure was running):

First is ok ... but second is undefined ... but why I have two errors not one I have no idea.

Maybe the problem is here, I raised exception inside your proc WebButton1Click like this:

procedure TForm1.WebButton1Click(Sender: TObject);
var
s: TObject;
str: string;
begin
//str := s.ToString;
raise Exception.Create('Error Message');
end;

and after that I see that AError is undefined:

Hi @brunofierens is it anough info for reproduce the problem?

It is on my todolist.

The problem here is that the window receives after the error another error of a different type PromiseRejectionEvent and this is a different object type than an error event. We'll add a detection and will skip to treat the JavaScript as an error object.

Ok ... thx for the info. Is there a chance that this issue will be resolved and included in the next release?

This is added and will be part of the next release.

Hi,

In version 2.0.3.0 if I raise exception like this:

procedure TForm1.WebButton1Click(Sender: TObject);
var
s: TObject;
str: string;
begin
//str := s.ToString;
raise Exception.Create('Error Message');
end;

the error object is now ok:
image

but now the AppException procedure is not fired.

Project for reproduce the same which is attached to this issue.

We further improved it for this case. Next update will address this.

Hi,

When do you plan next release updates?
This or next week?