【发布时间】:2017-01-24 04:36:09
【问题描述】:
我的 API 现在已关闭,由于 OPTIONS 调用得到 503,我的应用程序严重崩溃。在搜索高低后,我发现 Google 很难“捕获失败的选项调用”等人。没有收到一堆关于人们询问OPTIONS 调用是什么的帖子,或者更多关于将options 传递给API 调用的帖子。
那么,如何在我的代码中捕获失败的 OPTIONS 调用。这是一个示例 sn-p,其中调用失败。
const userPreferences = yield fetch(url, options).then((response) => response);
const result = yield userPreferences.json();
if (userPreferences.status !== 200) {
yield put(saveError(result));
} else {
yield put(savePreferences(result));
}
【问题讨论】:
-
yield的目的是什么?为什么不在.then()内执行操作? -
我发现在生成器函数中以这种方式阅读更容易。
-
您要确定什么?你试过
mode:"no-cors"吗?
标签: javascript http-options-method