我的目标是读取响应中返回的消息。我使用node-fetch,响应是gzipped格式的。这就是我到目前为止所知道的:
const response = await fetch(config.url, {
method: 'POST',
body: request,
headers: {'Content-Type': 'application/json; charset=UTF-8', 'x-tn-api_key':config.key, 'x-tn-api_signature':generateAPISignature()}
})
let deserializedResponse = await response.json()这是deserializedResponse的样子:
{
"timestamp": "2021-03-03T22:34:37.362+0000",
"status": 400,
"error": "Bad Request",
"message": "JSON parse error: Cannot deserialize instance of `xyz` out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `xyz` out of START_ARRAY token\n at [Source: (PushbackInputStream); line: 1, column: 1]",
"path": "/a/v1/events"
}消息字段有json解析错误,如何读取消息字段?基本上,如果调用失败,我希望记录消息以用于调试目的。
更新:我将请求对象硬编码为某个静态对象,但仍然得到相同的错误。当我复制粘贴相同的静态对象到Postman中时,它工作得很好。有人知道为什么body:request被读取为请求数组吗?这似乎就是错误的原因,因为它需要的是请求中的对象,而不是对象数组
发布于 2021-03-04 09:29:04
替换
body: request,使用
body: JSON.stringify(request),似乎解决了这个问题
https://stackoverflow.com/questions/66466103
复制相似问题