kittinunf / fuel

The easiest HTTP networking library for Kotlin/Android

Home Page:https://fuel.gitbook.io/documentation/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

non-FuelError Exceptions in request interceptors cause casting errors

jonesetc opened this issue · comments

Bug Report

Description

When an exception is thrown in a request interceptor, that runtime exception bubbles up until the point that it is assumed (inside of of fuel code) to be a FuelError, is unsafe cast as one, and causes a runtime error at the failed cast.

To Reproduce

Simple code to recreate:

val manager = FuelManager().apply {
    basePath = "https://example.com"
    addRequestInterceptor { { throw RuntimeException("oops") } }
}

runBlocking {
    manager.get("/").awaitStringResult()
}

Will throw error:

class java.lang.RuntimeException cannot be cast to class com.github.kittinunf.fuel.core.FuelError (java.lang.RuntimeException is in module java.base of loader 'bootstrap'; com.github.kittinunf.fuel.core.FuelError is in unnamed module of loader 'app')

Instead of throwing the expected RuntimeException wrapped in a FuelError.

Expected behavior

All non-FuelErrors should be wrapped in a FuelError and be handleable as FuelErrors in the request would be, and not have the failed cast.

Screenshots

N/A

Environment

Development Machine

  • OS: macos and linux
  • IDE: IntelliJ (and running live outside of IDE)
  • Fuel version: 2.3.1
  • Kotlin version: 1.7.10

Smartphone or Emulator

N/A

Additional context

The error is right here:

It seems as simple as changing this to:

.recover {
    if (it is FuelError) Result.Failure(it as FuelError)
    else Result.Failure(FuelError.wrap(it))
}

However I can't seem to get Fuel building locally because of "SDK location not found" at "build.gradle.kts:130" despite having the same JDK 11 set up that I use for everything else. So either feel free to crib that if it makes sense or any direction on how to set up a local build would be great and I'd put up a PR with a test immediately.

Thanks!