You can simply wrap the call in a try..except block, for example:
procedure TForm1.InvokeGet;
var
Response: TXDataClientResponse;
begin
try
Response := await(XDataWebClient1.GetAsync(SelectedEntitySet, '$filter=Bla eq 2', SelectedId));
except
on E: EXDataClientRequestException do
ShowMessage('Error ' + E.Message + ' with status code ' + IntToStr(E.ErrorResult.StatusCode));
end;
GetMemo.Lines.Text := TJSJson.stringify(Response.Result)
end;
Alternatively you can use TXDataWebClient.OnError
event as well:
procedure TForm1.XDataWebClient1Error(Error: TXDataClientError);
begin
ShowInfo(
Format('%s. RequestId: %s. Code: %s. Request Url: %s',
[Error.ErrorMessage, Error.RequestId, Error.ErrorCode, Error.RequestUrl]),
True
);
end;
The concept is illustrated in the demo at \demos\web\clientAsync\XDataWebClientAsyncDemo.dproj