add const val for error code

Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
sowjanyakch 2024-10-29 17:24:31 +01:00 committed by backportbot[bot]
parent bbcc3fb0a0
commit 1bf55f9071
2 changed files with 15 additions and 6 deletions

View file

@ -658,9 +658,17 @@ class ConversationInfoActivity :
WorkInfo.State.FAILED -> {
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()
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()
Snackbar.make(
binding.root,
R.string.nc_common_error_sorry,
Snackbar.LENGTH_LONG
).show()
}
}
else -> {

View file

@ -70,15 +70,15 @@ class LeaveConversationWorker(context: Context, workerParams: WorkerParameters)
override fun onError(e: Throwable) {
Log.e(TAG, "Failed to remove self from room", e)
val httpException = e as? HttpException
val errorData = if (httpException?.code() == 400) {
val errorData = if (httpException?.code() == HTTP_ERROR_CODE_400) {
Data.Builder()
.putString("error_type", ERROR_NO_OTHER_MODERATORS_OR_OWNERS_LEFT)
.build()
}
else {
} else {
Data.Builder()
.putString("error_type", ERROR_OTHER)
.build() }
.build()
}
result.set(Result.failure(errorData))
}
@ -97,5 +97,6 @@ class LeaveConversationWorker(context: Context, workerParams: WorkerParameters)
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"
const val HTTP_ERROR_CODE_400 = 400
}
}