fuel
fuel copied to clipboard
Throwing AssertionFailedError (opentest4j) inside FoldableResponseInterceptor causes ClassCastException
Bug Report
Description
When you throw AssertionFailedError
inside a FoldableResponseInterceptor
, you get a ClassCastException
at SuspendableRequest.kt:58
. This is because org.opentest4j:AssertionFailedError
extends AssertionError
extends Error
extends Throwable
, while FuelError
extends Exception
extends Throwable
, so casting AssertionFailedError
to FuelError
can never succeed.
Expected behaviour
Instead of a ClassCastException
, I expect to see the contents of the AssertionFailedError
.
However, FuelError
's constructor has a parameter exception: Throwable
that is passed to Exception
. Is there a big reason not to construct a new FuelError
, rather than trying to cast?
So instead of this:
.recover { Result.Failure(it as FuelError) }
Why not this?
.recover { Result.Failure(FuelError(it)) }
(or something like that)
To Reproduce
object interceptor: FoldableRequestInterceptor {
override fun invoke(next: RequestTransformer): RequestTransformer {
return { request: Request ->
throw org.opentest4j.AssertionFailedError(".")
next(request)
}
}
}
// ...
FuelManager.instance.addInterceptor(interceptor)
FuelManager.get("bla").response( /** ... **/ )
Environment
Development Machine
- OS: Ubuntu 20.04 on Windows 10 via WSL2
- IDE: IntelliJ
- Fuel version: 2.2
- Kotlin version: 1.3.71
Additional context
The use case is slightly convoluted -- I am unit testing Fuel by writing a RequestInterceptor, so I can inspect e.g. the path and throw an assertion fail if it's not what's expected. My current workaround involves using reflection to dig out the internal FuelError constructor and rethrowing, but I would certainly appreciate a less hacky way to do this.