diff --git a/app/src/main/java/com/ulascan/app/data/repository/UserRepository.kt b/app/src/main/java/com/ulascan/app/data/repository/UserRepository.kt index 0da2a69..11ca845 100644 --- a/app/src/main/java/com/ulascan/app/data/repository/UserRepository.kt +++ b/app/src/main/java/com/ulascan/app/data/repository/UserRepository.kt @@ -8,6 +8,7 @@ import com.ulascan.app.data.states.ResultState import com.ulascan.app.utils.getErrorMessage import kotlinx.coroutines.flow.Flow import retrofit2.HttpException +import java.io.IOException class UserRepository( private val userPreferences: UserPreferences, @@ -33,6 +34,10 @@ class UserRepository( } catch (error: HttpException) { userPreferences.clearToken() ResultState.Error(error.getErrorMessage()) + } catch (error: IOException) { + ResultState.Error("No internet connection. Please check your network and try again.") + } catch (error: Exception) { + ResultState.Error("An unexpected error occurred: ${error.localizedMessage}") } } } diff --git a/app/src/main/java/com/ulascan/app/data/repository/chat/AuthenticatedChatRepository.kt b/app/src/main/java/com/ulascan/app/data/repository/chat/AuthenticatedChatRepository.kt index a7e2cae..10a4556 100644 --- a/app/src/main/java/com/ulascan/app/data/repository/chat/AuthenticatedChatRepository.kt +++ b/app/src/main/java/com/ulascan/app/data/repository/chat/AuthenticatedChatRepository.kt @@ -12,6 +12,7 @@ import com.ulascan.app.data.states.ResultState import com.ulascan.app.utils.getErrorMessage import kotlinx.coroutines.flow.Flow import retrofit2.HttpException +import java.io.IOException class AuthenticatedChatRepository(private val apiService: ApiService) : UserChatRepository { override suspend fun getHistory(): ResultState { @@ -20,6 +21,10 @@ class AuthenticatedChatRepository(private val apiService: ApiService) : UserChat ResultState.Success(response) } catch (error: HttpException) { ResultState.Error(error.getErrorMessage()) + } catch (error: IOException) { + ResultState.Error("No internet connection. Please check your network and try again.") + } catch (error: Exception) { + ResultState.Error("An unexpected error occurred: ${error.localizedMessage}") } } @@ -36,6 +41,10 @@ class AuthenticatedChatRepository(private val apiService: ApiService) : UserChat ResultState.Success(response) } catch (error: HttpException) { ResultState.Error(error.getErrorMessage()) + } catch (error: IOException) { + ResultState.Error("No internet connection. Please check your network and try again.") + } catch (error: Exception) { + ResultState.Error("An unexpected error occurred: ${error.localizedMessage}") } } diff --git a/app/src/main/java/com/ulascan/app/data/repository/chat/GuestChatRepository.kt b/app/src/main/java/com/ulascan/app/data/repository/chat/GuestChatRepository.kt index 7e7cdb4..ab8c81c 100644 --- a/app/src/main/java/com/ulascan/app/data/repository/chat/GuestChatRepository.kt +++ b/app/src/main/java/com/ulascan/app/data/repository/chat/GuestChatRepository.kt @@ -6,6 +6,7 @@ import com.ulascan.app.data.repository.ChatRepository import com.ulascan.app.data.states.ResultState import com.ulascan.app.utils.getErrorMessage import retrofit2.HttpException +import java.io.IOException class GuestChatRepository(private val apiService: ApiService) : ChatRepository { @@ -15,6 +16,10 @@ class GuestChatRepository(private val apiService: ApiService) : ChatRepository { ResultState.Success(response) } catch (error: HttpException) { ResultState.Error(error.getErrorMessage()) + } catch (error: IOException) { + ResultState.Error("No internet connection. Please check your network and try again.") + } catch (error: Exception) { + ResultState.Error("An unexpected error occurred: ${error.localizedMessage}") } } diff --git a/app/src/main/java/com/ulascan/app/ui/screens/auth/login/LoginViewModel.kt b/app/src/main/java/com/ulascan/app/ui/screens/auth/login/LoginViewModel.kt index af288c7..7892c6d 100644 --- a/app/src/main/java/com/ulascan/app/ui/screens/auth/login/LoginViewModel.kt +++ b/app/src/main/java/com/ulascan/app/ui/screens/auth/login/LoginViewModel.kt @@ -10,6 +10,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch import retrofit2.HttpException +import java.io.IOException class LoginViewModel(private val userRepository: UserRepository) : ViewModel() { @@ -31,6 +32,9 @@ class LoginViewModel(private val userRepository: UserRepository) : ViewModel() { } } catch (e: HttpException) { _uiState.value = LoginUiState.Error(e.getErrorMessage()) + } catch (e: IOException) { + _uiState.value = + LoginUiState.Error("No internet connection. Please check your network and try again.") } catch (e: Exception) { _uiState.value = LoginUiState.Error(e.message ?: "Unknown error") }