fix crash in EditProfileViewModel
This commit is contained in:
parent
1f75ef7b2b
commit
1d28f4728f
|
@ -35,6 +35,7 @@ import io.reactivex.schedulers.Schedulers
|
||||||
import okhttp3.MediaType
|
import okhttp3.MediaType
|
||||||
import okhttp3.MultipartBody
|
import okhttp3.MultipartBody
|
||||||
import okhttp3.RequestBody
|
import okhttp3.RequestBody
|
||||||
|
import org.json.JSONException
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
import retrofit2.Callback
|
import retrofit2.Callback
|
||||||
|
@ -53,7 +54,7 @@ private const val TAG = "EditProfileViewModel"
|
||||||
class EditProfileViewModel @Inject constructor(
|
class EditProfileViewModel @Inject constructor(
|
||||||
private val mastodonApi: MastodonApi,
|
private val mastodonApi: MastodonApi,
|
||||||
private val eventHub: EventHub
|
private val eventHub: EventHub
|
||||||
): ViewModel() {
|
): ViewModel() {
|
||||||
|
|
||||||
val profileData = MutableLiveData<Resource<Account>>()
|
val profileData = MutableLiveData<Resource<Account>>()
|
||||||
val avatarData = MutableLiveData<Resource<Bitmap>>()
|
val avatarData = MutableLiveData<Resource<Bitmap>>()
|
||||||
|
@ -199,7 +200,11 @@ class EditProfileViewModel @Inject constructor(
|
||||||
if (!response.isSuccessful || newProfileData == null) {
|
if (!response.isSuccessful || newProfileData == null) {
|
||||||
val errorResponse = response.errorBody()?.string()
|
val errorResponse = response.errorBody()?.string()
|
||||||
val errorMsg = if(!errorResponse.isNullOrBlank()) {
|
val errorMsg = if(!errorResponse.isNullOrBlank()) {
|
||||||
|
try {
|
||||||
JSONObject(errorResponse).optString("error", null)
|
JSONObject(errorResponse).optString("error", null)
|
||||||
|
} catch (e: JSONException) {
|
||||||
|
null
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue