简体   繁体   中英

On kittinunf/fuel unable to revert answer body when http status < 200 || > 299

I'm using kittinunf/fuel to build up an app under Android.

Referring to the first example on documentation that I paste here:

import com.github.kittinunf.fuel.httpGet
import com.github.kittinunf.result.Result;
fun main(args: Array<String>) {
    val httpAsync = "https://httpbin.org/get"
        .httpGet()
        .responseString { request, response, result ->
            when (result) {
                is Result.Failure -> {
                    val ex = result.getException()
                    println(ex)
                }
                is Result.Success -> {
                    val data = result.get()
                    println(data)
                }
            }
        }
    httpAsync.join()
}

It's possible to revert the http message body with val data = result.get() also in case of an http status < 200 or > 299? Servers will often return extended error status message in the body and this is fully supported in iOS http stack.

In case of an error - following the example above - when result is Result.Failure response.body() contains the answer payload (identical as result.get() in case of Result.Success ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM