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:
Harsh Shandilya 2025-05-26 18:51:23 +05:30
parent 1db8067616
commit daf66a16bc
6 changed files with 25 additions and 21 deletions

View file

@ -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)

View 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")
}