I have the following code (FMX) - I need it to run on Win, iOS and Android, but testing on the Windows side looks like the exception is never trapped if the URL is wrong or server timeout, etc. How can I solve this? I haven't tested it on the mobile side yet, but assuming I may run into the same issues (or at least I don't want my users to).
Zack
function TTabbedForm.TestRestCall(): Boolean;
var
RESTClient: REST.Client.TRESTClient;
RESTRequest: REST.Client.TRESTRequest;
Authentication: REST.Authenticator.Simple.TSimpleAuthenticator;
res:Boolean;
begin
res:=False;
try
RESTClient:= TRESTClient.Create('http://api.test.com/ccd');
RESTRequest:= TRESTRequest.Create(nil);
RESTRequest.Method:= REST.Types.TRESTRequestMethod.rmGET;
RESTRequest.Accept:= 'application/json';
Authentication:= REST.Authenticator.Simple.TSimpleAuthenticator.Create(nil);
Authentication.Username := 'test';
Authentication.Password := 'test';
RESTClient.Authenticator := Authentication;
RESTRequest.Client:= RESTClient;
RESTRequest.OnHTTPProtocolError := Test(TRESTRequest);
RESTRequest.Execute;
res:=true;
except
res:=false;
end;
Result:=res;
end;