mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-21 20:45:29 +03:00
handle errors properly
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
9028ad0d1c
commit
bbcc3fb0a0
2 changed files with 20 additions and 8 deletions
|
@ -21,7 +21,6 @@ import android.view.MenuItem
|
|||
import android.view.View
|
||||
import android.view.View.GONE
|
||||
import android.view.View.VISIBLE
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
|
@ -657,11 +656,12 @@ class ConversationInfoActivity :
|
|||
startActivity(intent)
|
||||
}
|
||||
WorkInfo.State.FAILED -> {
|
||||
Toast.makeText(
|
||||
context,
|
||||
R.string.nc_last_moderator_leaving_room_warning,
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
val errorType = workInfo.outputData.getString("error_type")
|
||||
if (errorType == LeaveConversationWorker.ERROR_NO_OTHER_MODERATORS_OR_OWNERS_LEFT) {
|
||||
Snackbar.make( binding.root, R.string.nc_last_moderator_leaving_room_warning, Snackbar.LENGTH_LONG ).show()
|
||||
} else {
|
||||
Snackbar.make( binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG ).show()
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ package com.nextcloud.talk.jobs
|
|||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import androidx.work.Data
|
||||
import androidx.work.ListenableWorker
|
||||
import androidx.work.WorkerParameters
|
||||
import androidx.work.impl.utils.futures.SettableFuture
|
||||
|
@ -28,6 +29,7 @@ import io.reactivex.Observer
|
|||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import retrofit2.HttpException
|
||||
import javax.inject.Inject
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
|
@ -67,9 +69,17 @@ class LeaveConversationWorker(context: Context, workerParams: WorkerParameters)
|
|||
|
||||
override fun onError(e: Throwable) {
|
||||
Log.e(TAG, "Failed to remove self from room", e)
|
||||
if (e.message?.contains("HTTP 400") == true) {
|
||||
result.set(Result.failure())
|
||||
val httpException = e as? HttpException
|
||||
val errorData = if (httpException?.code() == 400) {
|
||||
Data.Builder()
|
||||
.putString("error_type", ERROR_NO_OTHER_MODERATORS_OR_OWNERS_LEFT)
|
||||
.build()
|
||||
}
|
||||
else {
|
||||
Data.Builder()
|
||||
.putString("error_type", ERROR_OTHER)
|
||||
.build() }
|
||||
result.set(Result.failure(errorData))
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
|
@ -85,5 +95,7 @@ class LeaveConversationWorker(context: Context, workerParams: WorkerParameters)
|
|||
|
||||
companion object {
|
||||
private const val TAG = "LeaveConversationWorker"
|
||||
const val ERROR_NO_OTHER_MODERATORS_OR_OWNERS_LEFT = "NO_OTHER_MODERATORS_OR_OWNERS_LEFT"
|
||||
const val ERROR_OTHER = "ERROR_OTHER"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue