Best way to show exceptions on TMS Web Core, returned from a XData REST Server Service Operation

Hi Guys

I'm evaluating TMS Web Core.

We've service operations made with XData, and some methods returns list of non entity objects.

We want to show those lists in a DBGrid using a dataset.

So far, we were able to use TWebClientConnection / TWebClientDataSet / TWebDataSource set, but the problem with TWebClientConnection is that the event OnConnectError only provides the ErrorCode, which simply returns 500 in case of a server exception.

The other alternative we tried was using a TXDataWebConnection / TXDataWebClient pair, calling RawInvoke. This way we have access to the error returned by the server, but to show the results in a grid with a dataset, we tried to use a TWebClientDataSet and assign the Rows property on RawInvoke success, but somehow it doesn't work.

The only solution we could find to achieve both goals was to fill a TWebStringGrid manually with the results of RawInvoke, but this is not definitely a good solution.

We are not sure if its worth to try TJQXWebGrid and its DataArray property.

Please take a look at the enclosed demo, any help would be greatly appreciated.

Thanks

WebCoreRESTDemo.zip (68.1 KB)

I'm sorry, the demo attached wasn't correct, uploaded a new one now. Thanks

WebCoreRESTDemo.zip (68.5 KB)

Using XData components (method 2) works fine here. It just needed some fine tuning. First, the XDataWebConnection1 was not active, so I connected it in OnCreate event:

procedure TDataModule1.WebDataModuleCreate(Sender: TObject);
begin
  XDataWebConnection1.Connected := True;
end;

Second, WebClientDataset2 was associated WebClientConnection2 which was active. This way a useless request is made and the dataset gets open. You should set disassociate both components by clearing Connection property of WebClientDataset2 at design time.

Finally, in WebButton2Click event, you need to be sure the dataset is closed before settings Rows:

procedure TForm4.WebButton2Click(Sender: TObject);
begin
  DataModule1.XDataWebClient1.RawInvoke('ITestService.GetUsers',[IntToStr(edtSerialNumber.Value)],
    procedure(bResponse: TXDataClientResponse)
    var
      obj: TJSObject;
      val: TJSArray;
    begin
      obj:= TJSObject(bResponse.Result);
      val:= TJSArray(TJSObject(obj['value']));
      
      // ADD THE FOLLOWING LINE
      DataModule1.WebClientDataSet2.Active:= False;

      DataModule1.WebClientDataSet2.Rows:= val;
      DataModule1.WebClientDataSet2.Active:= True;
    end,
    procedure(bError: TXDataClientError)
    begin
      WebMessageDlg1.ShowDialog(bError.ErrorMessage, mtError, [mbOk]);
    end);
end;

And everything should work fine.

2 Likes

Great thanks, it's working now.

Also works loading with TJQXGrid.Data.DataArray, btw

1 Like

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