isResponseSuccessful static method
Future<bool>
isResponseSuccessful(
- String url, {
- Duration? timeout,
- int? timeoutMillis,
- 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;
}