get<T> static method

Future<ApiResponse<T>> get<T>(
  1. String endpoint, {
  2. Map<String, String>? args,
  3. List<MultipartFile>? files,
  4. String? method,
  5. String? dataPath,
  6. String? errorPath,
})

Implementation

static Future<ApiResponse<T>> get<T>(String endpoint,
    {Map<String, String>? args,
    List<MultipartFile>? files,
    String? method,
    String? dataPath,
    String? errorPath}) async {
  ApiResponse<T> data;

  try {
    data = ApiResponse<T>(
        await _post(endpoint, body: args, files: files, method: method),
        dataPath: dataPath,
        errorPath: errorPath);
  } catch (e) {
    log(e.toString(), error: e);
    var obj = {"error": e.toString()};
    data = ApiResponse<T>(obj, errorPath: "error");
  }

  if (data.isSuccess) {
    return data;
  } else {
    log(data.error!);
    onError?.call(baseUri.toString() + endpoint, data.error);
    return Future.error(data.error!);
  }
}