I am building a simple android app using jetpack compose with MVVM architecture. For this I am using Retrofit2 for network request and Hilt for dependency injection. This App work fine while internet is available but when I turn off internet it crashes the App. So how to handle the network error while app is in offline mode ?
This is code for requesting data to API:
@Singleton
@Provides
fun provideRecipeService() : RecipeService {
return Retrofit.Builder()
.baseUrl("https://food2fork.ca/api/recipe/")
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(RecipeService::class.java)
}