handleException static method
String
handleException(
- DioException exception
)
Implementation
static String handleException(DioException exception) {
switch (exception.type) {
case DioExceptionType.connectionTimeout:
return "Connection Timeout. Please try again later.";
case DioExceptionType.sendTimeout:
return "Send Timeout. Please try again later.";
case DioExceptionType.receiveTimeout:
return "Receive Timeout. Please try again later.";
case DioExceptionType.badResponse:
// Handling HTTP status codes and errors
final statusCode = exception.response?.statusCode;
final statusMessage = exception.response?.statusMessage ?? "No message";
return "Error: $statusCode $statusMessage";
case DioExceptionType.cancel:
return "Request was cancelled";
case DioExceptionType.badCertificate:
return "Bad certificate. Please check your connection.";
case DioExceptionType.connectionError:
return "Connection Error. Please check your network.";
case DioExceptionType.unknown:
return _handleUnknownError(exception);
}
}