toResponse<T> static method

T toResponse<T>({
  1. required Object? object,
  2. required BaseServiceRequestParams params,
})

Parses a response object into a result of type T.

Handles various input types, including strings, maps, lists, and bytes, performing necessary conversions or JSON decoding.

Throws: RPCError if parsing fails.

Returns: The parsed response as an object of type T.

Implementation

static T toResponse<T>({
  required Object? object,
  required BaseServiceRequestParams params,
}) {
  try {
    return JsonParser.valueAs<T>(object);
  } catch (e) {
    throw RPCError(
      message: "Parsing response failed.",
      relatedNetwork: params.network,
      request: params.toJson(),
      details: {"error": e.toString(), "excepted": "$T"},
    );
  }
}