-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
如果接口:Failed to fetch错误,如何关闭连接?使用curRequestController.abort();未生效,请指教 #46
Comments
错误的情况,是不是自己就关闭了? |
那如果我想不让他一直尝试连接,设置 retry: false, 我看源码里是每隔一秒就尝试连接。这个能取消吗? |
/** |
谢谢! |
When I leave my website, an error is thrown: "The user aborted a request." |
onerror(err) {
// https://github1s.com/Azure/fetch-event-source/blob/HEAD/src/fetch.ts#L132-L133
// stop retrying
throw err
}, 不确定是不是你想要的,需要throw err 才不会重试 |
谢谢,已使用抛错解决过了 |
Yeah, this is a serious issue, bit me too: #54 |
const abortController = new AbortController();
const signal = abortController.signal;
const headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('x-client-token', token);
await fetchEventSource(Url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-client-token':
${token}
,},
body: JSON.stringify({ chat_detail_id: chat_detail_id }),
signal: signal,
retry: false,
async onopen(response) {
console.log('Open:', response);
if (
response.ok &&
response.headers.get('content-type') === 'text/event-stream'
) {
console.log("everything's good");
} else if (
response.status >= 400 &&
response.status < 500 &&
response.status !== 429
) {
console.log('请求错误');
} else {
console.log('其他错误');
}
},
async onerror(error) {
console.log('Error:', error);
abortController.abort();
},
});
The text was updated successfully, but these errors were encountered: