Fabian1648 2 Posted July 5, 2021 Hi, In an Android application, how can we catch the exception that is triggered when we make a REST request that remains unanswered. The following code does not work. When we launch the REST request, the app freezes until the REST timeout is exceeded and then Android displays a message "the app does not respond" try //Blabla... except on E: Exception do begin //blabla... end; end; Share this post Link to post
vfbb 285 Posted July 6, 2021 (edited) If you set TRESTClient's SynchronizedEvents property to False, you can do this directly: // FRequest: TRESTRequest // FClient: TRESTClient // FCanRaiseException: Boolean = {$IFDEF DEBUG}True{$ELSE}False{$ENDIF} function TryRequest: Boolean begin FClient.SynchronizedEvents := False; FRequest.Client := FClient; try FRequest.Execute; except on E: ERESTException do begin if FCanRaiseException then Exception.RaiseOuterException(Exception.Create('Service or connection failed')) else Exit(False); end; end; Result := True; end; This code is blocking, so it must be executed in a task in the background, and communicating with the UI through a queue. Just a question, what rest api do you is integrating? You may be able to make this integration faster with the Refit library: viniciusfbb/ipub-refit: Simple way to consume REST services (github.com) Edited July 6, 2021 by vfbb 1 1 Share this post Link to post
Guest Posted July 6, 2021 3 hours ago, vfbb said: You may be able to make this integration faster with the Refit library: viniciusfbb/ipub-refit: Simple way to consume REST services (github.com) Well, i hate attributes so much, that i put it in the top 25 out of 99 nasty stuff in Delphi. But the way you used them is pretty neat and cool ! Share this post Link to post
Lars Fosdal 1792 Posted July 7, 2021 I split the Attribute discussion into a separat thread Share this post Link to post