let fetchResponse;
try {
fetchResponse = await fetch(url, {
method: 'POST',
headers: {
'Content-type': 'application/json',
Accept: 'application/json,*/*;q=0.0',
},
body: JSON.stringify(codeConversionInputMsg),
});
} catch (error) {
throw new FetchApiErrorWrapper(); // (dont worry, this line doesnt reach, its not the problem)
}
500
fetchResponse.text()
看看里面有什么fetchResponse.text()
抛出错误fetchResponse.text()
Uncaught (in promise) TypeError: Body is unusable
} else if (fetchResponse.status >= 400 && fetchResponse.status < 600) {
let msg
try {
msg = await fetchResponse.text(); // << here is the problem
} catch (error) {
msg = undefined; // this line is never reached
}
}
fetch() 函数的返回值是一个解析为 Response 对象的 Promise。 然后您将使用这个 Response 对象。请参阅示例。您都做错了,因此请使用示例进行更正。