mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 14:07:05 +05:30
refactor: move HttpFailure.toError to api
module
Also expose EitherNet as an api dependency since it's part of the public API.
This commit is contained in:
parent
1db8067616
commit
daf66a16bc
6 changed files with 25 additions and 21 deletions
|
@ -20,12 +20,12 @@ anvil { generateDaggerFactories.set(true) }
|
|||
|
||||
dependencies {
|
||||
api(libs.dagger)
|
||||
api(libs.eithernet)
|
||||
api(libs.javax.inject)
|
||||
api(libs.okhttp.core)
|
||||
api(libs.retrofit)
|
||||
api(projects.model)
|
||||
|
||||
implementation(libs.eithernet)
|
||||
implementation(libs.eithernet.integration.retrofit)
|
||||
implementation(libs.jsoup)
|
||||
|
||||
|
|
21
api/src/main/kotlin/dev/msfjarvis/claw/api/util.kt
Normal file
21
api/src/main/kotlin/dev/msfjarvis/claw/api/util.kt
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright © Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.api
|
||||
|
||||
import com.slack.eithernet.ApiResult.Failure
|
||||
import java.io.IOException
|
||||
import java.net.HttpURLConnection
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE") // We inline this to eliminate the stacktrace frame.
|
||||
inline fun <T : Any> Failure.HttpFailure<T>.toError(): Throwable =
|
||||
when (code) {
|
||||
HttpURLConnection.HTTP_NOT_FOUND -> IOException("Story was removed by moderator")
|
||||
HttpURLConnection.HTTP_INTERNAL_ERROR,
|
||||
HttpURLConnection.HTTP_BAD_GATEWAY,
|
||||
HttpURLConnection.HTTP_UNAVAILABLE -> IOException("It appears lobste.rs is currently down")
|
||||
else -> IOException("API returned an invalid response")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue