Bimba.git

commit 493fbd994ee09140a949218cff81babc6237657d

Author: Adam <git@apiote.xyz>

error handling in suggestions

%!v(PANIC=String method: strings: negative Repeat count)


diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/home/HomeViewModel.kt b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/home/HomeViewModel.kt
index 72f6efd2bb9b254905f1172adef1f9ac98a07ba0..443ebc8e2c12439df37017e014c15e9e8be758bb 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/home/HomeViewModel.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/home/HomeViewModel.kt
@@ -12,7 +12,13 @@ import androidx.lifecycle.MutableLiveData
 import androidx.lifecycle.ViewModel
 import androidx.lifecycle.viewModelScope
 import kotlinx.coroutines.launch
-import xyz.apiote.bimba.czwek.api.*
+import xyz.apiote.bimba.czwek.api.ErrorResponse
+import xyz.apiote.bimba.czwek.api.QueryableV1
+import xyz.apiote.bimba.czwek.api.QueryablesResponse
+import xyz.apiote.bimba.czwek.api.QueryablesResponseDev
+import xyz.apiote.bimba.czwek.api.QueryablesResponseV1
+import xyz.apiote.bimba.czwek.api.Server
+import xyz.apiote.bimba.czwek.api.queryQueryables
 
 class HomeViewModel : ViewModel() {
 	private val mutableQueryables = MutableLiveData<List<QueryableV1>>()
@@ -22,14 +28,10 @@ 	fun getQueryables(cm: ConnectivityManager, server: Server, query: String) {
 		viewModelScope.launch {
 			val result = queryQueryables(cm, server, query, limit = 6)
 			if (result.error != null) {
-				// note intentionally no error showing in suggestions
+				// xxx intentionally no error showing in suggestions
 				if (result.stream != null) {
-					Log.e("Suggestion", "${b2s(result.stream.readBytes())}")
-					return@launch
-					Log.e(
-						"Suggestion",
-						"${result.error.statusCode}, ${ErrorResponse.unmarshal(result.stream).message}"
-					)
+					val response = ErrorResponse.unmarshal(result.stream)
+					Log.e("Suggestion", "${result.error.statusCode}, ${response.message}")
 				} else {
 					Log.e("Suggestion", "${result.error.statusCode}")
 				}
@@ -42,18 +44,6 @@ 						else -> null
 					}
 			}
 		}
-	}
-
-	private fun b2s(b: ByteArray): String {
-		var s = ""
-		b.forEach {
-			if (it in 32..127) {
-				s += Char(it.toInt())
-			} else {
-				s += "\\x$it"
-			}
-		}
-		return s
 	}
 
 	inner class SearchBarWatcher(