You are not logged in.
Pages: 1
I'm checking for connection to rest server using ServerTimestampSynchronize as documented:
/// you can call this method to call the remote URI root/Timestamp
// - this can be an handy way of testing the connection, since this method
// is always available, even without authentication
// - returns TRUE if the client time correction has been retrieved
// - returns FALSE on any connection error - check LastErrorMessage and
// LastErrorException to find out the exact connection error
function ServerTimestampSynchronize: boolean;
so how can I reconnect to the rest when I get an error calling ServerTimestampSynchronize method. I can't find the Close method in TSQLRestClientURI.
connector := TSQLHttpClientWebsockets.Create(AnsiString(host), AnsiString(port), serverAccess, ssl, '', '', 5000, 5000, 10000);
Offline
Using the Demos\ThirdParty\Goerge demo.
1. I'm starting the server Websocket/Json
2. Starting client
3. Clicked the SUM method - response is ok
4. Closed the server
5. Started server
6. Clicked the SUM method - an error occured:
---------------------------
Debugger Exception Notification
---------------------------
Project mORMotRESTcl.exe raised exception class EInterfaceFactoryException with message 'TInterfacedObjectFakeClient.FakeCall(IRestMethods.Sum) failed: 'URI service/RestMethods.Sum [80.6,12.3] returned status 'Not Found' (404 - Network problem or request timeout)''.
---------------------------
Break Continue Help
---------------------------
So I thought that I have to close the REST client connection after I get that error. What's the other solution? Free the client and recreate an object again?
Offline
You have to handle network errors, in that 3rd party example you're using interface based services so if you restart the server like that it's best to re-create the client.
Offline
I thought so.
I've implemented it like that:
fClient.OnFailed := Err;
procedure tRestClient.Err(Sender: TSQLRestClientURI; E: Exception;
Call: PSQLRestURIParams);
begin
if not StatusCodeIsSuccess(Call.OutStatus) then
postmessage(Form1.Handle, WM_FAIL, 0, 0);
end;
procedure TForm1.RestartClient(var message: TMessage); message WM_FAIL;
begin
StartStopClient(Restart);
end;
that's correct procedure?
Last edited by radexpol (2020-12-20 21:20:41)
Offline
yes that should work (for that specific example), Err event could be called several times so you should make sure the postmessage is sent only once when needed.
Last edited by pvn0 (2020-12-20 21:30:43)
Offline
Hi @radexpol
I implemented this event to handle ORM reconnections in my project. It is called when a request occurs and returns an error, it worked ok, however this request which triggered the error event, it is not executed. You know how to fire a request of your own that fired the error event?
I don't know if I was too confused eheheh
Offline
Pages: 1