TsgcWSPServer_WAMP › Methods › CallError
Sends a CALLERROR reply (message type 4) to the caller when the remote procedure could not be executed or finished unsuccessfully.
procedure CallError(const aCallId, aErrorURI, aErrorDesc: String; const aErrorDetails: String = '');
| Name | Type | Description |
|---|---|---|
aCallId | const String | Identifier generated by the client when it originally invoked the remote procedure; used to correlate the error reply with the pending call. |
aErrorURI | const String | URI (or CURIE) that uniquely identifies the error class, for example http://example.com/error#not_authorized. |
aErrorDesc | const String | Human-readable description of the error, useful for logging and debugging. |
aErrorDetails | const String | Optional application-specific error payload (for example a JSON object with extra context). Pass an empty string when not needed. |
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.
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;