TsgcWSPServer_WAMP方法 › CallError

CallError 方法

当远程过程无法执行或执行失败时,向调用方发送 CALLERROR 回复(消息类型 4)。

语法

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

参数

名称类型描述
aCallIdconst String客户端最初调用远程过程时生成的标识符;用于将错误回复与挂起的调用关联起来。
aErrorURIconst String唯一标识错误类别的 URI(或 CURIE),例如 http://example.com/error#not_authorized
aErrorDescconst String错误的人类可读描述,可用于日志记录和调试。
aErrorDetailsconst String可选的特定于应用程序的错误载荷(例如包含额外上下文的 JSON 对象)。不需要时传入空字符串。

备注

当 RPC 无法完成时(参数无效、授权缺失、内部异常、超时等),从 OnCall 处理程序内部(通常从 except 分支)调用 CallError。服务器向调用者写入 WAMP CALLERROR[4, CallID, ErrorURI, ErrorDesc, ErrorDetails],并从待处理列表中删除该调用,这意味着对于同一个 aCallId,不能再发送进一步的 CallResultCallProgressResult。如果 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;

返回方法