jrgonzalez
07/12/2022, 4:33 PMraulraja
07/12/2022, 4:55 PMjrgonzalez
07/12/2022, 4:56 PMsuspend inline fun <reified R, reified A> get(
url: Url,
acceptedErrorCodes: List<Int> = emptyList()
): Effect<BackendFailure<R>, A> =
effect {
try {
val httpResponse: HttpResponse = getHttpResponse(url)
val httpStatusCode: HttpStatusCode = httpResponse.status
if (httpStatusCode.isSuccess() || httpStatusCode.value in acceptedErrorCodes) {
when (val backendResponse: BackendResponse<R, A> = httpResponse.body()) {
is BackendResponse.Failure -> shift(BackendFailure.Known(backendResponse.data))
is BackendResponse.Success -> backendResponse.data
}
} else {
shift(BackendFailure.Unknown(null))
}
} catch (throwable: Throwable) {
shift(BackendFailure.Unknown(throwable.nonFatalOrThrow().message))
}
}
jrgonzalez
07/12/2022, 4:57 PMshift
. As soon as it goes through them it produces a stacktrace like the one I gave most of the timesjrgonzalez
07/12/2022, 4:58 PMshift<A>(BackendFailure.Unknown(null))
as first line on the try
block sometimes works though, but other times it fails too which is odd cause it should not have reached any ktor-dependent code by then (first ktor call is on the getHttpResponse
which is a simple ktor’s httpClient.get(url)
)raulraja
07/12/2022, 5:31 PMraulraja
07/12/2022, 5:31 PMjrgonzalez
07/12/2022, 5:32 PMjrgonzalez
07/12/2022, 5:33 PMraulraja
07/12/2022, 5:34 PMjrgonzalez
07/12/2022, 5:36 PMjrgonzalez
07/12/2022, 5:38 PMraulraja
07/12/2022, 5:40 PMjrgonzalez
07/12/2022, 5:50 PMjrgonzalez
07/12/2022, 5:50 PMraulraja
07/12/2022, 5:54 PMjrgonzalez
07/12/2022, 6:08 PMjrgonzalez
07/12/2022, 6:08 PM