Skip to content

Commit d9896b6

Browse files
liveHarshitiamareebjamal
authored andcommitted
fix: Display unauthorization error while loading events (#2110)
1 parent 1e35275 commit d9896b6

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

app/src/main/java/org/fossasia/openevent/general/attendees/AttendeeViewModel.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.fossasia.openevent.general.order.OrderService
2424
import org.fossasia.openevent.general.ticket.Ticket
2525
import org.fossasia.openevent.general.ticket.TicketService
2626
import org.fossasia.openevent.general.utils.HttpErrors
27+
import retrofit2.HttpException
2728
import timber.log.Timber
2829

2930
const val ORDER_STATUS_PENDING = "pending"
@@ -175,8 +176,9 @@ class AttendeeViewModel(
175176
}, {
176177
mutableProgress.value = false
177178
if (createAttendeeIterations + 1 == totalAttendee)
178-
if (it.message.equals(HttpErrors.CONFLICT)) {
179-
mutableTicketSoldOut.value = true
179+
if (it is HttpException) {
180+
if (it.code() == HttpErrors.CONFLICT)
181+
mutableTicketSoldOut.value = true
180182
} else {
181183
mutableMessage.value = resource.getString(R.string.create_attendee_fail_message)
182184
Timber.d(it, "Failed")

app/src/main/java/org/fossasia/openevent/general/event/EventsViewModel.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import org.fossasia.openevent.general.data.Resource
2222
import org.fossasia.openevent.general.event.paging.EventsDataSourceFactory
2323
import org.fossasia.openevent.general.notification.NotificationService
2424
import org.fossasia.openevent.general.search.location.SAVED_LOCATION
25+
import org.fossasia.openevent.general.utils.HttpErrors
2526
import org.fossasia.openevent.general.utils.extensions.withDefaultSchedulers
27+
import retrofit2.HttpException
2628
import timber.log.Timber
2729

2830
const val NEW_NOTIFICATIONS = "newNotifications"
@@ -134,10 +136,28 @@ class EventsViewModel(
134136
}
135137
}
136138
}, {
139+
if (it is HttpException) {
140+
if (authHolder.isLoggedIn() && it.code() == HttpErrors.UNAUTHORIZED) {
141+
logoutAndRefresh()
142+
}
143+
}
137144
Timber.e(it, "Error fetching notifications")
138145
})
139146
}
140147

148+
private fun logoutAndRefresh() {
149+
compositeDisposable += authService.logout()
150+
.withDefaultSchedulers()
151+
.subscribe({
152+
loadLocationEvents()
153+
syncNotifications()
154+
}, {
155+
mutableProgress.value = false
156+
Timber.e(it, "Error while logout")
157+
mutableMessage.value = resource.getString(R.string.error)
158+
})
159+
}
160+
141161
fun checkAndReset(token: String, newPassword: String) {
142162
val resetRequest = RequestPasswordReset(PasswordReset(token, newPassword))
143163
if (authHolder.isLoggedIn()) {

app/src/main/java/org/fossasia/openevent/general/utils/AppLinkUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ object AppLinkUtils {
2424
}
2525

2626
fun handleIntent(intent: Intent?, navController: NavController) {
27-
val uri = intent?.data.toString()
28-
val data = getData(uri) ?: return
27+
val uri = intent?.data ?: return
28+
val data = getData(uri.toString()) ?: return
2929
val bundle = Bundle()
3030
bundle.putString(data.argumentKey, data.argumentValue)
3131
navController.navigate(data.destinationId, bundle)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.fossasia.openevent.general.utils
22

33
object HttpErrors {
4-
const val CONFLICT = "HTTP 409 CONFLICT"
4+
const val CONFLICT = 409
5+
const val UNAUTHORIZED = 401
56
}

0 commit comments

Comments
 (0)