handle method

Future<void> handle(
  1. String? path
)

Implementation

Future<void> handle(String? path) async {
  try {
    _logger.info(
      'Handles RPC response',
    );

    final handler = _handlerForPath(path);
    if (handler == null) {
      throw DeeplinkRpcFailure(
        code: DeeplinkRpcFailure.kInvalidRequest,
        message: 'No handler for path $path',
      );
    }

    final data = handler.route.getData(path);

    if (data == null) {
      throw const DeeplinkRpcFailure(
        code: DeeplinkRpcFailure.kInvalidRequest,
        message: 'Failed to extract data from path',
      );
    }

    final response = DeeplinkRpcResponse.decode(data);

    await handler.handle(response);

    _logger.info(
      'RPC call handled',
    );
  } catch (e, stack) {
    _logger.info(
      'An error occured',
      e,
      stack,
    );
    throw const DeeplinkRpcResult.failure(
      failure: DeeplinkRpcFailure(
        code: DeeplinkRpcFailure.kServerError,
      ),
    );
  }
}