getData<T> method

Future<T> getData<T>({
  1. required String path,
  2. required T builder(
    1. dynamic data
    ),
  3. Options? options,
})

Implementation

Future<T> getData<T>({
  required String path,
  required T Function(dynamic data) builder,
  Options? options,
}) async {
  try {
    var reponse = await dio.get(path, options: options ?? _options);

    switch (reponse.statusCode) {
      case 200:
        var data = json.decode(reponse.data);
        return builder(data);
      case 401:
        throw const APIError.invalidApiKey();
      case 404:
        throw const APIError.notFound();
      default:
        throw const APIError.unknown();
    }
  } on SocketException catch (_) {
    throw const APIError.noInternetConnection();
  }
}