Skip to content

Instantly share code, notes, and snippets.

@nadar71
Created November 10, 2020 15:19
Show Gist options
  • Save nadar71/78d836701709b0f68199e198fedeaadb to your computer and use it in GitHub Desktop.
Save nadar71/78d836701709b0f68199e198fedeaadb to your computer and use it in GitHub Desktop.
coroutines exception handling
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