Hi I have a delete request that works fine, but when I make subsequent delete calls to an item that has already been deleted in the API, I get an Exception, and the app crashes. I tried handling the error using Try/Catch with different exceptions eg(HttpException, IOException, etc) to prevent the app from crashing but it doesn't seem to work.
private fun deleteFavourite(
favourite: GetFavourite?,
viewModel: WallpapersSharedViewModel
) {
//handling 404 error in case of subsequent Delete request
try {
if (favourite != null && !favourite.isEmpty()) {
val favouriteId = favourite.get(0).id
viewModel.deleteFavourite(favouriteId)
Log.i("hiiiiyaa", "deleted${favouriteId}")
}
}
catch (e: HttpException){
Log.i("hiiiiyaa", "cannot find item to delete in the Api")
}
}
Error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.catexplorer, PID: 28492
retrofit2.HttpException: HTTP 400
at retrofit2.KotlinExtensions$await$2$2.onResponse(KotlinExtensions.kt:53)
at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:161)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
............