我正在对一个服务进行restful调用,并获得500个状态代码。回复如下:
{
"error": true,
"message": "Test error",
data: null
}
我使用以下代码到JavaScript端读取错误,但无法达到预期的结果。
fetch('your-api-endpoint')
.then(response => {
if (!response.ok) {
return Promise.reject(response)
}
return response.json(); // or response.text() depending on the response content type
})
.then(data => {
// Handle successful response data
console.log(data);
})
.catch(error => {
//How to read the actual response and print it ?
});
})
我想读取响应并显示
message
所有物但这一承诺从未得到解决。请帮忙