TsgcWSPServer_WAMP › 方法 › CallError
当远程过程无法执行或执行失败时,向调用方发送 CALLERROR 回复(消息类型 4)。
procedure CallError(const aCallId, aErrorURI, aErrorDesc: String; const aErrorDetails: String = '');
| 名称 | 类型 | 描述 |
|---|---|---|
aCallId | const String | 客户端最初调用远程过程时生成的标识符;用于将错误回复与挂起的调用关联起来。 |
aErrorURI | const String | 唯一标识错误类别的 URI(或 CURIE),例如 http://example.com/error#not_authorized。 |
aErrorDesc | const String | 错误的人类可读描述,可用于日志记录和调试。 |
aErrorDetails | const String | 可选的特定于应用程序的错误载荷(例如包含额外上下文的 JSON 对象)。不需要时传入空字符串。 |
当 RPC 无法完成时(参数无效、授权缺失、内部异常、超时等),从 OnCall 处理程序内部(通常从 except 分支)调用 CallError。服务器向调用者写入 WAMP CALLERROR 帧 [4, CallID, ErrorURI, ErrorDesc, ErrorDetails],并从待处理列表中删除该调用,这意味着对于同一个 aCallId,不能再发送进一步的 CallResult 或 CallProgressResult。如果 aCallId 未知(已回复、已取消或从未注册),该方法不执行任何操作。
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;