Bimba.git

commit ac5b34e76183470cc78d69d207016d7690b64466

Author: Adam <git@apiote.xyz>

change names of exceptions

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


diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/api/Responses.kt b/app/src/main/java/xyz/apiote/bimba/czwek/api/Responses.kt
index 995a8f761ebe42cc963f9d6b8a12d0973f2316e0..857ffaa118e479acfaf37876af655c1f64f962ee 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/api/Responses.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/api/Responses.kt
@@ -147,7 +147,7 @@ 						queryables.add(StopV1.unmarshal(stream))
 					}
 
 					else -> {
-						throw UnknownResourceVersion("Queryable/$r", 1u)
+						throw UnknownResourceVersionException("Queryable/$r", 1u)
 					}
 				}
 			}
@@ -173,7 +173,7 @@ 						queryables.add(LineV1.unmarshal(stream))
 					}
 
 					else -> {
-						throw UnknownResourceVersion("Queryable/$r", 1u)
+						throw UnknownResourceVersionException("Queryable/$r", 1u)
 					}
 				}
 			}
@@ -273,7 +273,7 @@ 						locatables.add(VehicleV1.unmarshal(stream))
 					}
 
 					else -> {
-						throw UnknownResourceVersion("Locatable/$r", 1u)
+						throw UnknownResourceVersionException("Locatable/$r", 1u)
 					}
 				}
 			}
@@ -299,7 +299,7 @@ 						locatables.add(VehicleV2.unmarshal(stream))
 					}
 
 					else -> {
-						throw UnknownResourceVersion("Locatable/$r", 1u)
+						throw UnknownResourceVersionException("Locatable/$r", 1u)
 					}
 				}
 			}




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 2761f6ac89092ffcc5218e8b2efcabfe2f249297..25298232b91abb5e997c6d68aab5d87aac285a51 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
@@ -14,9 +14,11 @@ import java.util.*
 import kotlin.reflect.KClass
 
 class TrafficFormatException(override val message: String) : IllegalArgumentException()
-class UnknownResourceVersion(val resource: String, val version: ULong) : Exception()
+class UnknownResourceVersionException(resource: String, val version: ULong) :
+	Exception("unknown version $version of $resource")
 
-class UnknownResource(val resource: String, val cls: KClass<*>) : Exception()
+class UnknownResourceException(resource: String, cls: KClass<*>) :
+	Exception("unknown class $cls for $resource")
 
 data class BimbaInfo(
 	val contact: Map<String, String>,
@@ -518,7 +520,7 @@ 			return when (type) {
 				0u -> valueOf("UNKNOWN")
 				1u -> valueOf("TRAM")
 				2u -> valueOf("BUS")
-				else -> throw UnknownResourceVersion("LineType/$type", 1u)
+				else -> throw UnknownResourceVersionException("LineType/$type", 1u)
 			}
 		}
 	}
@@ -534,7 +536,7 @@ 				0u -> valueOf("UNKNOWN")
 				1u -> valueOf("TRAM")
 				2u -> valueOf("BUS")
 				3u -> valueOf("TROLLEYBUS")
-				else -> throw UnknownResourceVersion("LineType/$type", 1u)
+				else -> throw UnknownResourceVersionException("LineType/$type", 1u)
 			}
 		}
 	}




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 89db0abb858d11cb2cfa1150591d0ff53eeeb0d5..4120a5f52b1467770aa4e7fee92f54bbe6c6d5d7 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,7 @@ import androidx.lifecycle.MutableLiveData
 import androidx.lifecycle.ViewModel
 import androidx.lifecycle.viewModelScope
 import kotlinx.coroutines.launch
-import xyz.apiote.bimba.czwek.repo.ErrorResponseError
+import xyz.apiote.bimba.czwek.repo.TrafficResponseException
 import xyz.apiote.bimba.czwek.repo.OnlineRepository
 import xyz.apiote.bimba.czwek.repo.Queryable
 
@@ -25,7 +25,7 @@ 		viewModelScope.launch {
 			try {
 				val repository = OnlineRepository()
 				mutableQueryables.value = repository.queryQueryables(cm, query, context) ?: emptyList()
-			} catch (e: ErrorResponseError) {
+			} catch (e: TrafficResponseException) {
 				// xxx intentionally no error showing in suggestions
 				Log.e("Suggestion", "$e")
 			}




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/map/MapViewModel.kt b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/map/MapViewModel.kt
index 50eb6a889b34dfc238ff57b48b3d0a6d70f8286d..bacd215fbb6a60598adbcc17ffb0d8696b05c5d0 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/map/MapViewModel.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/map/MapViewModel.kt
@@ -22,7 +22,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment
 import kotlinx.coroutines.launch
 import xyz.apiote.bimba.czwek.R
 import xyz.apiote.bimba.czwek.departures.DeparturesActivity
-import xyz.apiote.bimba.czwek.repo.ErrorResponseError
+import xyz.apiote.bimba.czwek.repo.TrafficResponseException
 import xyz.apiote.bimba.czwek.repo.Locatable
 import xyz.apiote.bimba.czwek.repo.OnlineRepository
 import xyz.apiote.bimba.czwek.repo.Position
@@ -40,7 +40,7 @@ 			viewModelScope.launch {
 				try {
 					val repository = OnlineRepository()
 					_locatables.value = repository.getLocatablesIn(cm, bl, tr, context) ?: emptyList()
-				} catch (e: ErrorResponseError) {
+				} catch (e: TrafficResponseException) {
 					Log.w("Map", "$e")
 				}
 			}




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesActivity.kt b/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesActivity.kt
index 499074ee40192d3c10c16413cd45dd371ca24f2f..b5d8fa38ecb1f8bd03fc66e5799258041b5cd1d8 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesActivity.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesActivity.kt
@@ -18,7 +18,7 @@ import xyz.apiote.bimba.czwek.R
 import xyz.apiote.bimba.czwek.api.*
 import xyz.apiote.bimba.czwek.databinding.ActivityDeparturesBinding
 import xyz.apiote.bimba.czwek.repo.Departure
-import xyz.apiote.bimba.czwek.repo.ErrorResponseError
+import xyz.apiote.bimba.czwek.repo.TrafficResponseException
 import xyz.apiote.bimba.czwek.repo.OnlineRepository
 import xyz.apiote.bimba.czwek.repo.Stop
 
@@ -125,7 +125,7 @@ 				val stopDepartures =
 					repository.getDepartures(cm, getFeedID(), getCode(), getLine(), this@DeparturesActivity)
 				updateItems(stopDepartures!!.departures, stopDepartures.stop)
 				openBottomSheet?.departureID()?.let { adapter.get(it) }?.let { openBottomSheet?.update(it) }
-			} catch (e: ErrorResponseError) {
+			} catch (e: TrafficResponseException) {
 				showError(e.error)
 				Log.w("Departures", "$e")
 			}




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/repo/Departure.kt b/app/src/main/java/xyz/apiote/bimba/czwek/repo/Departure.kt
index 92cee3af3c4ee80616516019a22c6818e07d17b9..c640b83234c78c51f8cf6ad09565d8e6e6c5f605 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/repo/Departure.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/repo/Departure.kt
@@ -9,7 +9,7 @@ import xyz.apiote.bimba.czwek.api.AlertV1
 import xyz.apiote.bimba.czwek.api.DepartureV1
 import xyz.apiote.bimba.czwek.api.DepartureV2
 import xyz.apiote.bimba.czwek.api.Time
-import xyz.apiote.bimba.czwek.api.UnknownResourceVersion
+import xyz.apiote.bimba.czwek.api.UnknownResourceVersionException
 import java.time.Instant
 import java.time.ZoneId
 import java.time.ZonedDateTime
@@ -122,7 +122,7 @@
 			1u -> context?.getString(R.string.departure_momentarily) ?: "momentarily"
 			2u -> context?.getString(R.string.departure_now) ?: "now"
 			3u -> context?.getString(R.string.departure_departed) ?: "departed"
-			else -> throw UnknownResourceVersion("VehicleStatus/$r", 1u)
+			else -> throw UnknownResourceVersionException("VehicleStatus/$r", 1u)
 		}
 	}
 




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/repo/ErrorResponseError.kt b/app/src/main/java/xyz/apiote/bimba/czwek/repo/ErrorResponseError.kt
deleted file mode 100644
index 2afa66348ce58ae93a9863b6cb2449df1468059d..0000000000000000000000000000000000000000
--- a/app/src/main/java/xyz/apiote/bimba/czwek/repo/ErrorResponseError.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-package xyz.apiote.bimba.czwek.repo
-
-import xyz.apiote.bimba.czwek.api.Error
-
-// todo that's a terrible name
-
-class ErrorResponseError(private val code: Int, private val msg: String, val error: Error) :
-	Exception() {
-	override fun toString(): String {
-		return "Error response with code $code: $msg"
-	}
-}
\ No newline at end of file




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 5f664f1057566ab0c53d3c848483e6a0c54dc338..42539d9c5f88ab95a59d71f63069c00b436a10df 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,7 +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.UnknownResourceException
 import xyz.apiote.bimba.czwek.api.VehicleV1
 import xyz.apiote.bimba.czwek.api.VehicleV2
 
@@ -41,9 +41,9 @@ 			xyz.apiote.bimba.czwek.api.getDepartures(cm, Server.get(context), feedID, stop, line)
 		if (result.error != null) {
 			if (result.stream != null) {
 				val response = withContext(Dispatchers.IO) { ErrorResponse.unmarshal(result.stream) }
-				throw ErrorResponseError(result.error.statusCode, response.message, result.error)
+				throw TrafficResponseException(result.error.statusCode, response.message, result.error)
 			} else {
-				throw ErrorResponseError(result.error.statusCode, "", result.error)
+				throw TrafficResponseException(result.error.statusCode, "", result.error)
 			}
 		} else {
 			return when (val response =
@@ -78,9 +78,9 @@ 		)
 		if (result.error != null) {
 			if (result.stream != null) {
 				val response = withContext(Dispatchers.IO) { ErrorResponse.unmarshal(result.stream) }
-				throw ErrorResponseError(result.error.statusCode, response.message, result.error)
+				throw TrafficResponseException(result.error.statusCode, response.message, result.error)
 			} else {
-				throw ErrorResponseError(result.error.statusCode, "", result.error)
+				throw TrafficResponseException(result.error.statusCode, "", result.error)
 			}
 		} else {
 			return when (val response =
@@ -89,7 +89,7 @@ 				is LocatablesResponseDev -> response.locatables.map {
 					when (it) {
 						is StopV2 -> Stop(it)
 						is VehicleV2 -> Vehicle(it)
-						else -> throw UnknownResource("locatables", it::class)
+						else -> throw UnknownResourceException("locatables", it::class)
 					}
 				}
 
@@ -97,7 +97,7 @@ 				is LocatablesResponseV1 -> response.locatables.map {
 					when (it) {
 						is StopV1 -> Stop(it)
 						is VehicleV1 -> Vehicle(it)
-						else -> throw UnknownResource("locatables", it::class)
+						else -> throw UnknownResourceException("locatables", it::class)
 					}
 				}
 
@@ -113,9 +113,9 @@ 		val result = xyz.apiote.bimba.czwek.api.getLine(cm, Server.get(context), feedID, line)
 		if (result.error != null) {
 			if (result.stream != null) {
 				val response = withContext(Dispatchers.IO) { ErrorResponse.unmarshal(result.stream) }
-				throw ErrorResponseError(result.error.statusCode, response.message, result.error)
+				throw TrafficResponseException(result.error.statusCode, response.message, result.error)
 			} else {
-				throw ErrorResponseError(result.error.statusCode, "", result.error)
+				throw TrafficResponseException(result.error.statusCode, "", result.error)
 			}
 		} else {
 			return when (val response =
@@ -156,9 +156,9 @@ 		}
 		if (result.error != null) {
 			if (result.stream != null) {
 				val response = withContext(Dispatchers.IO) { ErrorResponse.unmarshal(result.stream) }
-				throw ErrorResponseError(result.error.statusCode, response.message, result.error)
+				throw TrafficResponseException(result.error.statusCode, response.message, result.error)
 			} else {
-				throw ErrorResponseError(result.error.statusCode, "", result.error)
+				throw TrafficResponseException(result.error.statusCode, "", result.error)
 			}
 		} else {
 			return when (val response =
@@ -167,14 +167,14 @@ 				is QueryablesResponseDev -> response.queryables.map {
 					when (it) {
 						is StopV2 -> Stop(it)
 						is LineV1 -> Line(it)
-						else -> throw UnknownResource("queryablesV2", it::class)
+						else -> throw UnknownResourceException("queryablesV2", it::class)
 					}
 				}
 
 				is QueryablesResponseV1 -> response.queryables.map {
 					when (it) {
 						is StopV1 -> Stop(it)
-						else -> throw UnknownResource("queryablesV1", it::class)
+						else -> throw UnknownResourceException("queryablesV1", it::class)
 					}
 				}
 




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/repo/TrafficResponseException.kt b/app/src/main/java/xyz/apiote/bimba/czwek/repo/TrafficResponseException.kt
new file mode 100644
index 0000000000000000000000000000000000000000..cc5d6bf9b530b1c9499ea2751d2a876fd90304fc
--- /dev/null
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/repo/TrafficResponseException.kt
@@ -0,0 +1,6 @@
+package xyz.apiote.bimba.czwek.repo
+
+import xyz.apiote.bimba.czwek.api.Error
+
+class TrafficResponseException(code: Int, msg: String, val error: Error) :
+	Exception("Error response with code $code: $msg")
\ No newline at end of file




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/search/LineGraphActivity.kt b/app/src/main/java/xyz/apiote/bimba/czwek/search/LineGraphActivity.kt
index eca856d9a9935795debc4854e5a37cf6e0fb283b..30a1cb40e6158088c853e36cd7079cd0577a8200 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/search/LineGraphActivity.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/search/LineGraphActivity.kt
@@ -12,8 +12,8 @@ import com.google.android.material.tabs.TabLayout
 import kotlinx.coroutines.MainScope
 import kotlinx.coroutines.launch
 import xyz.apiote.bimba.czwek.databinding.ActivityLineGraphBinding
-import xyz.apiote.bimba.czwek.repo.ErrorResponseError
 import xyz.apiote.bimba.czwek.repo.OnlineRepository
+import xyz.apiote.bimba.czwek.repo.TrafficResponseException
 import xyz.apiote.bimba.czwek.search.ui.SectionsPagerAdapter
 
 class LineGraphActivity : AppCompatActivity() {
@@ -53,7 +53,7 @@ 					tabs.setupWithViewPager(viewPager)
 					binding.lineOverlay.visibility = View.GONE
 					binding.viewPager.visibility = View.VISIBLE
 				}
-			} catch (e: ErrorResponseError) {
+			} catch (e: TrafficResponseException) {
 				showError(e.error)
 				Log.w("Line", "$e")
 			}




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/search/ResultsActivity.kt b/app/src/main/java/xyz/apiote/bimba/czwek/search/ResultsActivity.kt
index 0ee6c08c8d8cde67376458a865b9cf3f44cecf67..32ee74575ac55e9ae63bd0e6fd8f3cd53e78fc95 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/search/ResultsActivity.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/search/ResultsActivity.kt
@@ -18,7 +18,7 @@ import kotlinx.coroutines.*
 import xyz.apiote.bimba.czwek.R
 import xyz.apiote.bimba.czwek.api.*
 import xyz.apiote.bimba.czwek.databinding.ActivityResultsBinding
-import xyz.apiote.bimba.czwek.repo.ErrorResponseError
+import xyz.apiote.bimba.czwek.repo.TrafficResponseException
 import xyz.apiote.bimba.czwek.repo.OnlineRepository
 import xyz.apiote.bimba.czwek.repo.Position
 import xyz.apiote.bimba.czwek.repo.Queryable
@@ -123,7 +123,7 @@ 			try {
 				val repository = OnlineRepository()
 				val result = repository.queryQueryables(cm, query, context)
 				updateItems(result)
-			} catch (e: ErrorResponseError) {
+			} catch (e: TrafficResponseException) {
 				Log.w("Suggestion", "$e")
 				showError(e.error)
 			}
@@ -137,7 +137,7 @@ 			try {
 				val repository = OnlineRepository()
 				val result = repository.locateQueryables(cm, position, context)
 				updateItems(result)
-			} catch (e: ErrorResponseError) {
+			} catch (e: TrafficResponseException) {
 				Log.w("Suggestion", "$e")
 				showError(e.error)
 			}