retrofit icon indicating copy to clipboard operation
retrofit copied to clipboard

FATAL EXCEPTION: retrofit2.adapter.guava.HttpException: HTTP 400

Open SkylekFR opened this issue 3 years ago • 1 comments

Hello, i'm using retrofit with Guava call adapter. When i'm making a call that result to a no 2XX status code, i got a fatal exception.

2022-06-17 17:26:06.536 28946-28946/com.wimova.driver.staging E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.wimova.driver.staging, PID: 28946
    retrofit2.adapter.guava.HttpException: HTTP 400 
        at retrofit2.adapter.guava.GuavaCallAdapterFactory$BodyCallAdapter$1.onResponse(GuavaCallAdapterFactory.java:111)
        at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:161)
        at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)

I'm not wrapping my result class into a Response class.

 ListenableFuture<LoadResult<Integer, DriverPropositionResponse>> pageFuture = Futures.transform(
                HttpService.getInstance().service.getDriverPropositions(String.valueOf(nextPageNumber),limit, startDate, endDate),
                        this::toLoadResult, mBgExecutor);

        ListenableFuture<LoadResult<Integer, DriverPropositionResponse>> partialLoadResultFuture =
                Futures.catching(pageFuture, HttpException.class,
                        LoadResult.Error::new, mBgExecutor);

        return Futures.catching(partialLoadResultFuture,
                IOException.class, LoadResult.Error::new, mBgExecutor);

but i'm catching the result. The crash seems to happen in the call adapter factory code so I don't know how to fix this...

SkylekFR avatar Jun 17 '22 15:06 SkylekFR

It looks like your request body did not match the service content type

jessemoe avatar Jul 29 '22 12:07 jessemoe

I have the same issue

Fatal Exception: gt.a
Caused by retrofit2.HttpException: HTTP 400 
       at retrofit2.KotlinExtensions$await$2$2.onResponse(SourceFile:136)
       at retrofit2.OkHttpCall$1.onResponse(SourceFile:11)
       at com.google.firebase.perf.network.d.onResponse(SourceFile:17)
       at fv.e$a.run(SourceFile:41)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
       at java.lang.Thread.run(Thread.java:1012)

thuan-savvycom avatar Jan 11 '24 07:01 thuan-savvycom

Retrofit is not the cause of an HTTP 400 response. It means you and the target server disagree with how the request was formatted.

The original issue postulates that it's not possible to catch HTTP exceptions with the Guava adapter. We have tests which do exercise the non-200 case, but we rely on the exception being thrown from get() in the test.

If someone wants to write a test case based on ours that demonstrates the failure to capture an exception where the problem is within Retrofit I'd be more than happy to take a look.

JakeWharton avatar Jan 17 '24 16:01 JakeWharton