TsgcWSPServer_WAMPMethods › CallError

CallError Method

Sends a CALLERROR reply (message type 4) to the caller when the remote procedure could not be executed or finished unsuccessfully.

Syntax

procedure CallError(const aCallId, aErrorURI, aErrorDesc: String; const aErrorDetails: String = '');

Parameters

NameTypeDescription
aCallIdconst StringIdentifier generated by the client when it originally invoked the remote procedure; used to correlate the error reply with the pending call.
aErrorURIconst StringURI (or CURIE) that uniquely identifies the error class, for example http://example.com/error#not_authorized.
aErrorDescconst StringHuman-readable description of the error, useful for logging and debugging.
aErrorDetailsconst StringOptional application-specific error payload (for example a JSON object with extra context). Pass an empty string when not needed.

Remarks

Invoke CallError from inside an OnCall handler (typically from the except branch) when the RPC cannot be fulfilled: invalid arguments, missing authorization, internal exception, timeout, etc. The server writes a WAMP CALLERROR frame [4, CallID, ErrorURI, ErrorDesc, ErrorDetails] to the caller and removes the call from the pending list, which means no further CallResult or CallProgressResult can be sent for the same aCallId. If aCallId is unknown (already replied to, cancelled or never registered) the method does nothing.

Example

procedure TForm1.sgcWSPServer_WAMP1Call(Connection: TsgcWSConnection;
  const CallId, ProcURI: string; Arguments: TStringList);
begin
  try
    if ProcURI = 'com.example.divide' then
      sgcWSPServer_WAMP1.CallResult(CallId, IntToStr(10 div StrToInt(Arguments[0])));
  except
    on E: Exception do
      sgcWSPServer_WAMP1.CallError(CallId,
        'http://example.com/error#invalid_argument', E.Message, '');
  end;
end;

Back to Methods