#1 2020-05-29 12:22:59

damiand
Member
From: Greece
Registered: 2018-09-21
Posts: 94

Sample 14 - TSQLRestRoutingREST routing not supported by server

I was playing with Sample 14 - Inteface based services, using named pipe (Project14Client <-> Project14Server). When I deliberately changed the username in Client.SetUser method to User1, I got an - expected - exception, although the error message contained something more than the pure error json (with errorCode, errorText properties):

TServiceFactoryClient.Create(): ICalculator interface or TSQLRestRoutingREST routing not supported by server [{

"errorCode":403,

"errorText":"Authentication Failed: Invalid signature (0)"

}].

How can I get only the error message json as the exception message? Do I have to setup the server to explicitly support TSQLRestRoutingREST routing? If so, how?

Last edited by damiand (2020-05-29 21:05:53)

Offline

#2 2020-06-02 11:11:24

damiand
Member
From: Greece
Registered: 2018-09-21
Posts: 94

Re: Sample 14 - TSQLRestRoutingREST routing not supported by server

By taking a look at the mORMot.pas unit, line 61268 I presumed that the error json is by design embedded into the Exception Message and this was not caused by a routing misconfiguration:

...
  if PosEx(SERVICE_CONTRACT_NONE_EXPECTED,ContractExpected)=0 then begin
    if not InternalInvoke(SERVICE_PSEUDO_METHOD[imContract],
       TSQLRestClientURI(fRest).fServicePublishOwnInterfaces,@RemoteContract,@Error) then
      raise EServiceException.CreateUTF8('%.Create(): I% interface or % routing not '+
        'supported by server [%]',[self,fInterfaceURI,fRest.ServicesRouting,Error]);
...

So if I want to process the json error on the client side I have to extract it as a substring from the Exception error message by using something like this:

    try
      Client.ServiceDefine([ICalculator],sicShared);
    except on E: EServiceException do
// Extract the json as a substring from inside the brackets of E.Message
    end;

Is there any alternative, more orthodox approach? I attempted to use a PServiceRunningContext but with no success, since at the exception point all its record properties had nil values.

Offline

#3 2020-06-02 12:28:51

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Sample 14 - TSQLRestRoutingREST routing not supported by server

Don't rely on intercepting exceptions on client side.
Especially don't rely on implementation details of the framework on client side.
Check https://synopse.info/files/html/Synopse … l#TITL_165

I don't understand why you wrote about PServiceRunningContext, which is a server-side only feature.
It is always nil on the client side for sure.

The kind of exception you try to intercept is a low-level exception because the client and server don't have matching contract.
You can intercept it via the TSQLRestClientURI.OnFailed event.

Offline

#4 2020-06-07 06:25:59

damiand
Member
From: Greece
Registered: 2018-09-21
Posts: 94

Re: Sample 14 - TSQLRestRoutingREST routing not supported by server

The response of ab helped me to understand better the framework and more, to find the proper and simpler answer to my initial question: How to handle client to server authentication errors and get the error response. The solution is simple: Check the return value of Client.SetUser method and if false, get the error response by calling Client.LastErrorMessage. I should have known it, if I had read properly the documentation before playing with the Sample 14 code. roll

By the way, by assigning a procedure to the Client.OnFailed event, I also got the error response json from the Call^.OutBody property. Many thanks ab. smile

Offline

Board footer

Powered by FluxBB