TXDataWebDataSet LoadAsync issue

Hi,

When LoadAsync errors out, it throws an exception that seemingly can't be caught.

I'm assuming that this is something to do with a threading error.

Is there any way of doing this or workaround?

Thanks!

1 Like

Update:
As a workaround, I have used a TXDataWebClient to do a ListAsync and passed the resultant JSON to the dataset. This works and the exception can be caught.

I don't see an issue here, do you have steps to reproduce the problem? What code are you using? Nevertheless, I'm glad you worked around your issue.

Hi Wagner,

Thanks for the reply.

I've set up a new project and added this routine:

procedure TForm2.WebButton1Click(Sender: TObject);
begin
  try
    //XDataWebConnection set up code
    XDataWebDataSet1.Connection:=XDataWebConnection1;
    XDataWebDataSet1.EntitySetName:='myEntity';
    XDataWebDataSet1.QueryString:='$filter=hello eq ''world''';
    await(XDataWebDataSet1.LoadAsync);
    ShowMessage(XDataWebDataSet1.FieldByName('hello').AsString);
  except
    on E:Exception do
      ShowMessage(E.Message);
    on E:EXDataClientRequestException do
      ShowMessage(E.Message);
  end;
end;

If I set up a breakpoint on the LoadAsync and disconnect connection to my server, walking through the LoadAsync call, it calls DoError from XData.Web.Client, where an EXDataClientRequestException is thrown, but the exception is not caught in the try catch block.

Thank you for the details. Indeed, there was a problem with the way LoadAsync method was handling the connection errors. Fix will be included in next release.

If you want to fix it right now yourself, you should patch the following line in unit XData.Web.Dataset.pas (then one in source\core\web folder, pay attention as there is another one in source\core folder), here is the correct method:

function TXDataWebDataSet.LoadAsync: TJSPromise;
begin
  Result := TJSPromise.new(
    procedure(ASuccess, AFailed: TJSPromiseResolver)
    begin
      EnsureConnected(
        procedure
        begin
          FOpenResolver := ASuccess;
          try
            inherited Load([], nil);
          except
            on E: Exception do
            begin
              if Assigned(AFailed) then
                AFailed(E)
              else
                raise;
            end;
          end;
        end,
        procedure(Error: TXDataWebConnectionError)
        begin
          AFailed(EXDataWebConnectionException.Create(Error));
        end);
    end)
end;

The line you should update is this one:

        AFailed(EXDataWebConnectionException.Create(Error));

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.