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

标签 http elasticsearch kotlin fuel

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

{
  "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
}

这是我的代码:
        val (request, response, result) = fullUrl
            .httpPut()
            .body(payload)
            .responseString()

        val (bytes, error) = result

        print(error)

相反,我看到的是:
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)

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

最佳答案

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

关于http - 在Kotlin Fuel中的http响应中看不到错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57185214/

相关文章:

eclipse - 未解析的引用 : pow in Eclipse using Kotlin

arrays - Kotlin 中使用 For 循环将 Int 数组元素插入 String 列表的问题(使用了 toString)

android - 尝试使用 Observable 时获取 Fata 信号 11

c# - Response.Redirect HTTP 状态码

linux - 使用 netcat (nc) 作为 HTTP 代理服务器和监视器

elasticsearch - 在 Elasticsearch 中过滤没有分数的查询

elasticsearch - 尝试将数据发送到Elasticsearch时Logstash挂起

android - 如何使用单独的线程来执行http请求

http - 仅为主页域从 HTTPS 重定向到 HTTP

Elasticsearch 自定义评分脚本——检查字段是否存在?