android– 燃料在出错时得到身体反应

android– 燃料在出错时得到身体反应,第1张

概述我怎样才能做到这一点?这是我正在做的请求.Fuel.get(url).timeout(TIMEOUT).body(myRequest.parameters!!,Charsets.UTF_8).responseString(){_,response,result->Log.e("result","$result")when(result){

我怎样才能做到这一点?这是我正在做的请求.

Fuel.get(url)    .timeout(TIMEOUT)    .body(myRequest.parameters!!, Charsets.UTF_8)    .responseString() { _, response, result ->                Log.e("result", "$result")                when (result) {                    is Result.Success -> {                        completionHandler(result.get(), null)                    }                    is Result.Failure -> {                        Log.e("fail", "${response}")                        completionHandler(null, Error(response.responseMessage))                    }                }            }

我得到的回应是:

Response : Bad RequestLength : 122Body : ({"message":"You have already booked that iceCream"})headers : (9)Connection : [keep-alive]Content-Length : [122]Content-Type : [application/Json; charset=utf-8]Date : [Thu, 03 May 2018 07:33:21 GMT]Server : [Nginx/1.12.1]

我想将正文消息作为我的错误返回.

解决方法:

如果您的代码使用awaitByteArrayResponse并得到Result<?,FuelError>>或FuelError对象,试试这个:

val(内容,错误)=结果//结果<?,FuelError>>
val strContent = error.errorData.toString(Charsets.UTF_8)

总结

以上是内存溢出为你收集整理的android – 燃料出错时得到身体反应全部内容,希望文章能够帮你解决android – 燃料在出错时得到身体反应所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1118551.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存