sendError method
Future
sendError(
- int id,
- String topic,
- String method,
- JsonRpcError error, {
- EncodeOptions? encodeOptions,
- RpcOptions? rpcOptions,
- String? appLink,
override
Implementation
@override
Future<dynamic> sendError(
int id,
String topic,
String method,
JsonRpcError error, {
EncodeOptions? encodeOptions,
RpcOptions? rpcOptions,
String? appLink,
}) async {
final Map<String, dynamic> payload = JsonRpcUtils.formatJsonRpcError(
id,
error,
);
final String? message = await core.crypto.encode(
topic,
payload,
options: encodeOptions,
);
if (message == null) {
return;
}
core.logger.d(
'[$runtimeType] sendRequest appLink: $appLink, '
'id: $id topic: $topic, method: $method, error: $error',
);
if ((appLink ?? '').isNotEmpty) {
final redirectURL = ReownCoreUtils.getLinkModeURL(
appLink!,
topic,
message,
);
await ReownCoreUtils.openURL(redirectURL);
} else {
final fallbackMethod = MethodConstants.UNREGISTERED_METHOD;
final methodOpts = MethodConstants.RPC_OPTS[method];
final fallbackMethodOpts = MethodConstants.RPC_OPTS[fallbackMethod]!;
final relayOpts = methodOpts ?? fallbackMethodOpts;
final fallbackOpts = relayOpts['reject'] ?? relayOpts['res']!;
await core.relayClient.publish(
topic: topic,
message: message,
ttl: (rpcOptions ?? fallbackOpts).ttl,
tag: (rpcOptions ?? fallbackOpts).tag,
);
}
}