Bimba.git

commit 0bb91ee84f89f55b88c9fbaaf893556605dc118c

Author: Adam <git@apiote.xyz>

handle unknown resource

 app/src/main/java/xyz/apiote/bimba/czwek/api/Structs.kt | 3 
 app/src/main/java/xyz/apiote/bimba/czwek/repo/OnlineRepository.kt | 11 


diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/api/Structs.kt b/app/src/main/java/xyz/apiote/bimba/czwek/api/Structs.kt
index 90fe803508308ca2bca30cbc05c99c502d367a75..ad2f2ca2147befaa516f905eb052878bfa4293e7 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/api/Structs.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/api/Structs.kt
@@ -11,9 +11,12 @@ import java.time.ZonedDateTime
 import java.time.format.DateTimeFormatter
 import java.time.format.FormatStyle
 import java.util.*
+import kotlin.reflect.KClass
 
 class TrafficFormatException(override val message: String) : IllegalArgumentException()
 class UnknownResourceVersion(val resource: String, val version: ULong) : Exception()
+
+class UnknownResource(val resource: String, val cls: KClass<*>) : Exception()
 
 data class BimbaInfo(
 	val contact: Map<String, String>,




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/repo/OnlineRepository.kt b/app/src/main/java/xyz/apiote/bimba/czwek/repo/OnlineRepository.kt
index 7e228854d67caaaceb5534bab94da75ae7b47b42..5f664f1057566ab0c53d3c848483e6a0c54dc338 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/repo/OnlineRepository.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/repo/OnlineRepository.kt
@@ -22,6 +22,7 @@ import xyz.apiote.bimba.czwek.api.QueryablesResponseV1
 import xyz.apiote.bimba.czwek.api.Server
 import xyz.apiote.bimba.czwek.api.StopV1
 import xyz.apiote.bimba.czwek.api.StopV2
+import xyz.apiote.bimba.czwek.api.UnknownResource
 import xyz.apiote.bimba.czwek.api.VehicleV1
 import xyz.apiote.bimba.czwek.api.VehicleV2
 
@@ -88,7 +89,7 @@ 				is LocatablesResponseDev -> response.locatables.map {
 					when (it) {
 						is StopV2 -> Stop(it)
 						is VehicleV2 -> Vehicle(it)
-						else -> TODO("nothing else")
+						else -> throw UnknownResource("locatables", it::class)
 					}
 				}
 
@@ -96,7 +97,7 @@ 				is LocatablesResponseV1 -> response.locatables.map {
 					when (it) {
 						is StopV1 -> Stop(it)
 						is VehicleV1 -> Vehicle(it)
-						else -> TODO("nothing else")
+						else -> throw UnknownResource("locatables", it::class)
 					}
 				}
 
@@ -150,7 +151,7 @@ 			"locate" -> xyz.apiote.bimba.czwek.api.locateQueryables(
 				cm, Server.get(context), PositionV1(position!!.latitude, position.longitude)
 			)
 
-			else -> TODO("Throw")
+			else -> throw RuntimeException("Unknown query type $type")
 		}
 		if (result.error != null) {
 			if (result.stream != null) {
@@ -166,14 +167,14 @@ 				is QueryablesResponseDev -> response.queryables.map {
 					when (it) {
 						is StopV2 -> Stop(it)
 						is LineV1 -> Line(it)
-						else -> TODO("nothing else")
+						else -> throw UnknownResource("queryablesV2", it::class)
 					}
 				}
 
 				is QueryablesResponseV1 -> response.queryables.map {
 					when (it) {
 						is StopV1 -> Stop(it)
-						else -> TODO("nothing else")
+						else -> throw UnknownResource("queryablesV1", it::class)
 					}
 				}