get<T> method

Future<T> get<T>([
  1. int expectedStatusCode = 200
])

returns a result of T if response.statusCode equals to expectedStatusCode

throws PException otherwise

this will also check if defaultJsonDecoder has been set, if true then this uses it instead of jsonDecode

Implementation

Future<T> get<T>([int expectedStatusCode = 200]) async {
  final response = await this;

  if (response.statusCode != expectedStatusCode) {
    throw transformStatusCodeToException(
      statusCode: response.statusCode,
      responseBody: response.body,
    );
  }
  if (_jsonDecoder != null) {
    final decoded = await _jsonDecoder!(response.body);
    return decoded as T;
  }
  return jsonDecode(response.body) as T;
}