You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
794 B
22 lines
794 B
import 'dart:async';
|
|
import 'dart:io';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
/// User-facing message when an API/network request fails.
|
|
String connectionErrorMessage(Object error) {
|
|
if (error is SocketException ||
|
|
error is TimeoutException ||
|
|
error is http.ClientException ||
|
|
error is HandshakeException ||
|
|
error is TlsException) {
|
|
final msg = error.toString().toLowerCase();
|
|
if (msg.contains('host lookup') ||
|
|
msg.contains('no address associated with hostname')) {
|
|
return "This device can't resolve the server hostname. On an emulator, try setting DNS to 8.8.8.8 or use a real device.";
|
|
}
|
|
return 'Connection to server has broken. Check API URL and network.';
|
|
}
|
|
return 'Network error. Please check the API URL and try again.';
|
|
}
|