Skip to content

Commit

Permalink
Try to reproduce bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Foso committed Aug 26, 2024
1 parent 8e87e38 commit 237e213
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions example/AndroidOnlyExample/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("com.google.devtools.ksp") version "2.0.0-1.0.22"
id("com.google.devtools.ksp") version "2.0.20-1.0.24"
id("org.jetbrains.kotlin.plugin.serialization") version "2.0.0"
id("de.jensklingenberg.ktorfit") version "2.0.0"
id("de.jensklingenberg.ktorfit") version "2.0.1"
id("org.jetbrains.kotlin.plugin.compose") version "2.0.0"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,24 @@ import de.jensklingenberg.ktorfit.converter.FlowConverterFactory
import de.jensklingenberg.ktorfit.converter.ResponseConverterFactory
import de.jensklingenberg.ktorfit.ktorfit
import io.ktor.client.HttpClient
import io.ktor.client.plugins.HttpResponseValidator
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.serialization.kotlinx.json.json
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.launch
import kotlinx.serialization.json.Json

class MyCustomException(message: String) : Exception(message)

val ktorfit = ktorfit {

baseUrl(StarWarsApi.baseUrl)
httpClient(HttpClient {
HttpResponseValidator {
validateResponse { response ->
throw MyCustomException("My Custom Exception")
}
}
install(ContentNegotiation) {
json(Json { isLenient = true; ignoreUnknownKeys = true })
}
Expand Down Expand Up @@ -58,9 +68,18 @@ class MainActivity : ComponentActivity() {
}
}

val exceptionHandler = CoroutineExceptionHandler { _, exception ->
exception.printStackTrace()
}

lifecycleScope.launch {
peopleState.value = api.getPerson(1)
lifecycleScope.launch(exceptionHandler) {
try {
peopleState.value = api.getPerson(1)
} catch (e: MyCustomException) {
throw e
}
}


}
}
4 changes: 2 additions & 2 deletions example/AndroidOnlyExample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.4.1' apply false
id 'com.android.library' version '8.4.1' apply false
id 'com.android.application' version '8.4.2' apply false
id 'com.android.library' version '8.4.2' apply false
id 'org.jetbrains.kotlin.android' version '2.0.0' apply false
}

0 comments on commit 237e213

Please sign in to comment.