isResponseSuccessful static method

Future<bool> isResponseSuccessful(
  1. String url, {
  2. Duration? timeout,
  3. int? timeoutMillis,
  4. CheckMethod checkMethod = CheckMethod.OPTIONS,
})

Implementation

static Future<bool> isResponseSuccessful(String url,
    {Duration? timeout,
    int? timeoutMillis,
    CheckMethod checkMethod = CheckMethod.OPTIONS}) async {
  final future =
      checkMethod == CheckMethod.OPTIONS ? options(url) : head(url);
  if (timeoutMillis != null) timeout = Duration(milliseconds: timeoutMillis);
  final response = await (timeout == null
      ? future
      : future.timeout(timeout,
          onTimeout: () => http.Response('', HttpStatus.requestTimeout)));
  return response.statusCode >= 200 || response.statusCode < 300;
}