toResponse<T> method
Implementation
BaseServiceResponse<T> toResponse<T>(Object? body, [int? statusCode]) {
statusCode ??= 200;
if (!ServiceProviderUtils.isSuccessStatusCode(statusCode)) {
return ServiceErrorResponse(
statusCode: statusCode,
error: ServiceProviderUtils.findError(
object: body,
statusCode: statusCode,
),
);
}
try {
T response;
if (body is List<int>) {
response = ServiceProviderUtils.toResult<T>(body);
} else {
response = ServiceProviderUtils.parseResponse<T>(
object: body,
params: this,
);
}
return ServiceSuccessRespose<T>(
statusCode: statusCode,
response: response,
);
} catch (_) {}
throw RPCError(
message: "Parsing response failed.",
request: toJson(),
details: {"expected": "$T"},
);
}