Browse Source
try-catch for anonymous user parsing
renovate/org.jetbrains.kotlinx-kotlinx-coroutines-test-1.x
Austin Huang
4 years ago
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
2 changed files with
52 additions and
44 deletions
-
app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt
-
app/src/main/java/awais/instagrabber/webservices/GraphQLRepository.kt
|
|
@ -222,7 +222,7 @@ class ProfileFragmentViewModel( |
|
|
|
private suspend fun fetchUser( |
|
|
|
currentUser: User?, |
|
|
|
stateUsername: String, |
|
|
|
): User { |
|
|
|
): User? { |
|
|
|
if (currentUser != null) { |
|
|
|
// logged in |
|
|
|
val tempUser = userRepository.getUsernameInfo(stateUsername) |
|
|
|
|
|
@ -178,12 +178,15 @@ open class GraphQLRepository(private val service: GraphQLService) { |
|
|
|
// TODO convert string response to a response class |
|
|
|
open suspend fun fetchUser( |
|
|
|
username: String, |
|
|
|
): User { |
|
|
|
): User? { |
|
|
|
val response = service.getUser(username) |
|
|
|
val body = JSONObject(response |
|
|
|
try { |
|
|
|
val body = JSONObject( |
|
|
|
response |
|
|
|
.split("<script type=\"text/javascript\">window._sharedData = ").get(1) |
|
|
|
.split("</script>").get(0) |
|
|
|
.trim().replace(Regex("\\};$"), "}")) |
|
|
|
.trim().replace(Regex("\\};$"), "}") |
|
|
|
) |
|
|
|
val userJson = body |
|
|
|
.getJSONObject("entry_data") |
|
|
|
.getJSONArray("ProfilePage") |
|
|
@ -224,6 +227,11 @@ open class GraphQLRepository(private val service: GraphQLService) { |
|
|
|
externalUrl = url, |
|
|
|
) |
|
|
|
} |
|
|
|
catch (e: Exception) { |
|
|
|
Log.e(TAG, "fetchUser failed", e) |
|
|
|
return null |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// TODO convert string response to a response class |
|
|
|
suspend fun fetchPost( |
|
|
|