Fetch API 如何在catch中获取response body?

Fetch API how to get response body in catch?

我从服务器得到这样的响应:

Request URL:http://api.bfexchange.net/wallet/balance
Request Method:GET
Status Code:504 Gateway Time-out
Remote Address:52.78.140.154:80
Referrer Policy:no-referrer-when-downgrade

但是在 fetch API 的 catch 中打印错误只是 returns 个错误对象。

fetch(...)
.then(...)
.catch((err) => {
    console.dir(err);
});

它打印这个(来自 Google Chrome):

TypeError: Failed to fetch
    message: "Failed to fetch"
    stack: "TypeError: Failed to fetch"
    __proto__: Error
index.js:82 

我想获得正确错误处理的状态代码,比如服务器没有响应之类的东西。

在这种情况下,有没有办法获取响应数据?否则,我可以尝试哪些替代方案?

任何建议将不胜感激!

如果服务器使用 CORS,您将收到 5xx 响应,但不会被视为拒绝;承诺将通过回应来解决。如果服务器不使用 CORS,你将永远看不到响应并且承诺将始终被拒绝(除非你使用 "no-cors",在这种情况下你可以获得在某些服务工作者场景中有用的不透明响应).