Created
November 10, 2020 15:19
-
-
Save nadar71/78d836701709b0f68199e198fedeaadb to your computer and use it in GitHub Desktop.
coroutines exception handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val exceptionHandler = CoroutineExceptionHandler { _, exception -> | |
LogHelper.log(TAG, "User Observer Exception: ${exception.stackTrace}", Log.ERROR) | |
} | |
private suspend fun userHasClientCodes(user : FirebaseUser, request: UsersRequest, token : String): String? = | |
withContext(Dispatchers.IO+ exceptionHandler) { | |
val response = CustomerAreaAPI.createUser(request, "Bearer ${token}") | |
if (response != null && response !is String) { | |
if (AppPreferences.firstTimeNotification == 0) { | |
AppPreferences.firstTimeNotification = 1 | |
sendNotificationToken(AppPreferences.notificationToken, baseContext) | |
} | |
var data = (response as ServerResponse<UsersResponse>).data | |
if (data!!.customerCodes.isNullOrEmpty()) { | |
return@withContext "false" | |
} | |
return@withContext "true" | |
} | |
return@withContext response as? String | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment