isEndpointAvailable method

Future<String> isEndpointAvailable(
  1. BuildContext context
)

Checks if the Gemma API endpoint is available. Returns a localized success message if the endpoint is reachable, or an error message if not.

context: The BuildContext used for localization.

Implementation

Future<String> isEndpointAvailable(BuildContext context) async {
  final url = '$baseUrl/health';
  try {
    final response =
        await http.get(Uri.parse(url)).timeout(Duration(seconds: 200));
    if (response.statusCode == 200) {
      // return 'Success';
      return AppLocalizations.of(context)!.defaults_success;
    } else {
      // return 'Error occurred while trying to connect to the server. Status code: ${response.statusCode}';
      return AppLocalizations.of(context)!
          .aiGenerationAPIGemma_errorresponse1(response.statusCode);
    }
  } catch (e) {
    // return 'Error occurred while trying to connect to the server: $e';
    return AppLocalizations.of(context)!
        .aiGenerationAPIGemma_errorresponse2(e.toString());
  }
}