toEncodingResponse<T> method
Converts a BaseServiceResponse into the specified encoding type.
The target encoding can be provided via encoding or inferred
from the responseEncoding. Common output types include bytes,
strings, maps, and arrays.
Implementation
T toEncodingResponse<T>(
BaseServiceResponse response, {
ServiceReponseEncoding? encoding,
}) {
return switch (response) {
BaseServiceErrorResponse() => throw _error(response),
BaseServiceSuccessRespose() => () {
try {
return response.toEncodingResponse(encoding ?? responseEncoding);
} catch (e) {
throw RPCError(
message: "Parsing response failed.",
request: toJson(),
relatedNetwork: network,
statusCode: response.statusCode,
details: {
"encoding": encoding?.name ?? responseEncoding.name,
"response": response.runtimeType.toString(),
},
);
}
}(),
};
}