首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Kotlin Fuel中看不到http响应中的错误消息

在Kotlin Fuel中看不到http响应中的错误消息
EN

Stack Overflow用户
提问于 2019-07-24 22:23:44
回答 1查看 1.5K关注 0票数 0

我正在使用Kotlin上的Fuel库向我的Elasticsearch服务器发送HTTP PUT请求。但是,如果服务器返回404或400,我看不到错误正文。我希望收到类似以下内容的错误消息:

代码语言:javascript
复制
{
  "error": {
    "root_cause": [
      {
        "type": "invalid_snapshot_name_exception",
        "reason": "[snap1:kopya3]Invalid snapshot name [kopya3], snapshot with the same name already exists"
      }
    ],
    "type": "invalid_snapshot_name_exception",
    "reason": "[snap1:kopya3]Invalid snapshot name [kopya3], snapshot with the same name already exists"
  },
  "status": 400
}

下面是我的代码:

代码语言:javascript
复制
        val (request, response, result) = fullUrl
            .httpPut()
            .body(payload)
            .responseString()

        val (bytes, error) = result

        print(error)

相反,我看到的是:

代码语言:javascript
复制
HTTP Exception 400 Bad Request
    com.github.kittinunf.fuel.core.FuelError$Companion.wrap(FuelError.kt:84)
    com.github.kittinunf.fuel.core.DeserializableKt.response(Deserializable.kt:168)
    com.github.kittinunf.fuel.core.requests.DefaultRequest.responseString(DefaultRequest.kt:475)
    com.a.b.c.d.model.Cluster.createSnapshot(Cluster.kt:67)
    com.a.b.c.d.model.Cluster.createSnapshot$default(Cluster.kt:57)
    com.a.b.c.d.model.ClusterKt.main(Cluster.kt:85)
Caused by: HTTP Exception 400 Bad Request
    com.github.kittinunf.fuel.core.FuelError$Companion.wrap(FuelError.kt:86)
Caused by: com.github.kittinunf.fuel.core.HttpException: HTTP Exception 400 Bad Request
    com.github.kittinunf.fuel.core.requests.RequestTask.prepareResponse(RequestTask.kt:35)
    com.github.kittinunf.fuel.core.requests.RequestTask.call(RequestTask.kt:47)
    com.github.kittinunf.fuel.core.requests.RequestTask.call(RequestTask.kt:14)
    com.github.kittinunf.fuel.core.DeserializableKt.response(Deserializable.kt:166)
    com.github.kittinunf.fuel.core.requests.DefaultRequest.responseString(DefaultRequest.kt:475)
    com.a.b.c.d.model.Cluster.createSnapshot(Cluster.kt:67)
    com.a.b.c.d.model.Cluster.createSnapshot$default(Cluster.kt:57)
    com.a.b.c.d.model.ClusterKt.main(Cluster.kt:85)

如何查看实际的错误消息?提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-25 16:03:58

我通过查看response.data解决了这个问题,它是一个字节数组。通过String(response.data)将其转换为字符串,我可以看到错误消息。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57185214

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档