【发布时间】:2017-09-22 12:33:45
【问题描述】:
如何在 fetch 语句中记录错误响应?
我的代码如下所示:
eturn fetch('myurl.com', {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
}).then((response) => response.json())
.then((responseData) => {
console.log(responseData); // This logs nothing
}).catch((error) => {
console.log("Error " + error); // This logs something
});
我的代码示例中的日志是Error SyntaxError: JSON Parse error: Unrecognized token '<'。我认为这是因为 XDebug 发送了一些错误消息,但我绝对不知道可能出了什么问题。看起来响应以'
是否可以显示此响应?这对找出我的错误非常有用。
【问题讨论】:
-
为了调试去掉
.then((response) => response.json())部分,调试后把它带回来
标签: react-native error-handling fetch xdebug