Browse Source

hide exceptions internally behind `strictMode` param

main
James Fenn 1 year ago
parent
commit
1d57585911
2 changed files with 11 additions and 5 deletions
  1. +2
    -1
      example-android/src/main/java/me/jfenn/gitrest/example/android/MainActivity.kt
  2. +9
    -4
      gitrest/src/commonMain/kotlin/me/jfenn/gitrest/RequestProviderDelegate.kt

+ 2
- 1
example-android/src/main/java/me/jfenn/gitrest/example/android/MainActivity.kt View File

@@ -24,7 +24,8 @@ class MainActivity : AppCompatActivity() {
val repos = listOf(
"github:fennifith/Attribouter",
"gitlab@salsa.debian.org:reproducible-builds/reproducible-website",
"gitea@code.horrific.dev:james/git-rest-wrapper"
"gitea@code.horrific.dev:james/git-rest-wrapper",
"gitlab@code.horrific.dev:james/git-rest-wrapper"
).map { delegate.getRepo(it) }

recycler?.post {


+ 9
- 4
gitrest/src/commonMain/kotlin/me/jfenn/gitrest/RequestProviderDelegate.kt View File

@@ -6,10 +6,10 @@ import me.jfenn.gitrest.impl.gitea.GiteaProvider
import me.jfenn.gitrest.impl.github.GithubProvider
import me.jfenn.gitrest.impl.gitlab.GitlabProvider
import me.jfenn.gitrest.model.*
import me.jfenn.gitrest.model.DelegateResource

class RequestProviderDelegate(
private val services: Array<ServiceBuilder<*>> = arrayOf(GithubProvider, GitlabProvider, GiteaProvider)
private val services: Array<ServiceBuilder<*>> = arrayOf(GithubProvider, GitlabProvider, GiteaProvider),
private val strictMode: Boolean = false
) : RequestProvider {

private val providers: MutableMap<String, RequestProvider> = HashMap()
@@ -28,8 +28,13 @@ class RequestProviderDelegate(
// - alternatively, determine from header info?
}

return block(provider, providerStr.id)?.also { resource ->
(resource as? DelegateResource)?.setId(providerStr)
return try {
block(provider, providerStr.id)?.also { resource ->
(resource as? DelegateResource)?.setId(providerStr)
}
} catch (e: Exception) {
if (strictMode) throw e
null
}
}



Loading…
Cancel
Save