简体   繁体   English

如何捕获OPTIONS方法调用

[英]How to catch OPTIONS method call

My API is down right now, and my app crashed spectacularly due to the OPTIONS call getting a 503. After searching high and low, I've discovered it is very hard to Google "Catch failed options call", et al. 我的API现在关闭了,由于OPTIONS调用得到503,我的应用崩溃了。在上下搜索之后,我发现Google很难“捕获失败的选项调用”等。 without getting a bunch of posts about people asking what the OPTIONS call is, or more posts about passing options to an API call. 而没有一堆关于人们询问OPTIONS调用是什么的帖子,或者一本关于将options传递给API调用的更多帖子。

So, how do I capture a failed OPTIONS call in my code. 因此,如何在代码中捕获失败的OPTIONS调用。 Here is a sample snippet from where a call is being made that fails. 这是从中进行呼叫失败的示例片段。

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));
}

You can't. 你不能 That's something your browser will do for you when trying to figure out things like CORS. 这是您的浏览器在尝试找出CORS之类的内容时会为您执行的操作。 Only your browser will get the response to that. 只有您的浏览器会得到响应。 It won't pass the results to your code. 它不会将结果传递给您的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM