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
f6489eb10d
commit
6c4685dce5
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
|
||||||
import android.view.View.GONE
|
import android.view.View.GONE
|
||||||
import android.view.View.VISIBLE
|
import android.view.View.VISIBLE
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.fragment.app.FragmentTransaction
|
import androidx.fragment.app.FragmentTransaction
|
||||||
|
@ -660,11 +659,12 @@ class ConversationInfoActivity :
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
WorkInfo.State.FAILED -> {
|
WorkInfo.State.FAILED -> {
|
||||||
Toast.makeText(
|
val errorType = workInfo.outputData.getString("error_type")
|
||||||
context,
|
if (errorType == LeaveConversationWorker.ERROR_NO_OTHER_MODERATORS_OR_OWNERS_LEFT) {
|
||||||
R.string.nc_last_moderator_leaving_room_warning,
|
Snackbar.make( binding.root, R.string.nc_last_moderator_leaving_room_warning, Snackbar.LENGTH_LONG ).show()
|
||||||
Toast.LENGTH_LONG
|
} else {
|
||||||
).show()
|
Snackbar.make( binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG ).show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ package com.nextcloud.talk.jobs
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.work.Data
|
||||||
import androidx.work.ListenableWorker
|
import androidx.work.ListenableWorker
|
||||||
import androidx.work.WorkerParameters
|
import androidx.work.WorkerParameters
|
||||||
import androidx.work.impl.utils.futures.SettableFuture
|
import androidx.work.impl.utils.futures.SettableFuture
|
||||||
|
@ -28,6 +29,7 @@ import io.reactivex.Observer
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
|
import retrofit2.HttpException
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@SuppressLint("RestrictedApi")
|
@SuppressLint("RestrictedApi")
|
||||||
|
@ -67,9 +69,17 @@ class LeaveConversationWorker(context: Context, workerParams: WorkerParameters)
|
||||||
|
|
||||||
override fun onError(e: Throwable) {
|
override fun onError(e: Throwable) {
|
||||||
Log.e(TAG, "Failed to remove self from room", e)
|
Log.e(TAG, "Failed to remove self from room", e)
|
||||||
if (e.message?.contains("HTTP 400") == true) {
|
val httpException = e as? HttpException
|
||||||
result.set(Result.failure())
|
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() {
|
override fun onComplete() {
|
||||||
|
@ -85,5 +95,7 @@ class LeaveConversationWorker(context: Context, workerParams: WorkerParameters)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "LeaveConversationWorker"
|
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