getWithQueryParams method

Future getWithQueryParams(
  1. Uri uri,
  2. Map<String, String> headers
)

Implementation

Future<dynamic> getWithQueryParams(
    Uri uri, Map<String, String> headers) async {
  return http
      .get(uri, headers: headers)
      .then((http.Response response) {
        final String res = response.body;
        final int statusCode = response.statusCode;
        if (statusCode < 200 || statusCode >= 400) {
          throw Exception(_decoder.convert(res)['error']['message']);
        }
        return res;
      })
      .catchError((onError) {
        if (onError.toString().toLowerCase().contains("socket")) {
          throw Exception("Server timeout");
        } else {
          throw Exception(onError.toString().replaceAll("Exception:", ""));
        }
      })
      .timeout(const Duration(seconds: 10))
      .catchError((onError) {
        if (onError.toString().toLowerCase().contains("timeout")) {
          throw Exception("Server timeout");
        } else {
          throw Exception(onError.toString().replaceAll("Exception:", ""));
        }
      });
}