sendError method
Future
sendError(
- int id,
- String topic,
- String method,
- JsonRpcError error, {
- EncodeOptions? encodeOptions,
- RpcOptions? rpcOptions,
- String? appLink,
- TVFData? tvf,
override
Implementation
@override
Future<dynamic> sendError(
int id,
String topic,
String method,
JsonRpcError error, {
EncodeOptions? encodeOptions,
RpcOptions? rpcOptions,
String? appLink,
TVFData? tvf,
}) async {
final Map<String, dynamic> payload = JsonRpcUtils.formatJsonRpcError(
id,
error,
);
final resultId = payload['id'] as int;
final isLinkMode = (appLink ?? '').isNotEmpty;
final String? message = await core.crypto.encode(
topic,
payload,
options: isLinkMode
? EncodeOptions(type: EncodeOptions.TYPE_2)
: encodeOptions,
);
if (message == null) {
return;
}
if (isLinkMode) {
final redirectURL = ReownCoreUtils.getLinkModeURL(
appLink!,
topic,
message,
);
await ReownCoreUtils.openURL(redirectURL);
// Send Event through Events SDK
core.events.recordEvent(LinkModeResponseEvent(
direction: 'sent',
correlationId: resultId,
method: method,
isRejected: _isSessionAuthRejectedError(method, error),
));
core.logger.d(
'[$runtimeType] sendError linkMode ($appLink), '
'id: $id topic: $topic, method: $method, error: $error',
);
} 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']!;
final ttl = (rpcOptions ?? fallbackOpts).ttl;
final tag = (rpcOptions ?? fallbackOpts).tag;
//
await core.relayClient.publish(
topic: topic,
message: message,
options: PublishOptions(
ttl: ttl,
tag: tag,
correlationId: resultId,
// tvf data is sent only on tvfMethods methods
tvf: _shouldSendTVF(tag) ? tvf?.toJson(includeAll: true) : null,
),
);
core.logger.d(
'[$runtimeType] sendError relayClient, '
'id: $id topic: $topic, method: $method, error: $error',
);
}
}