Comments (1)
看了官网的实例,似乎没办法获取到后端500报错的body中的detail,打印看过onopen中的response,似乎也没有参数能直接获取到
这个库的实现里面,会
- 先去执行fetch,拿到response,
- 把上一步拿到的response传给onopen去执行
- 处理流数据
- 依次执行onclose,dispose,resolve(这部分可以不用细究)
- 上面的几个步骤都在try中执行,catch住错误后如果不是内部主动中断请求,就会执行你传入的onerror
所以你如果希望获取到后端500报错的body中的detail,直接在onopen中从response中拿到即可(前提是你说的这个detail后端返回体中存在,假如你说的是后端返回的错误信息,我理解应该直接await response.json()即可拿到)
而且我发现onopen不抛异常的话onerror是捕获不了请求500的错误
根据上面说的执行逻辑, 你需要在onopen中判断响应是否是500,是的话抛出,才能在onerror中去捕获到,onerror中不负责对响应进行校验
from fetch-event-source.
Related Issues (20)
- Cannot find name 'ReadableStreamDefaultReadResult' HOT 1
- How to retry from within onmessage handler?
- In the process of obtaining information, switching to another tab at this time, and then returning, will cause the previous link to be disconnected and reconnected. How to prevent the request from being disconnected when returning from other tabs? HOT 2
- Properties Documentation HOT 3
- Exponential reconnect backoff HOT 2
- @microsoft/fetchEventSource dispose method always curRequestController.abort with console error log HOT 2
- Does React Native app supported? HOT 1
- Can it be achieved to interrupt or cancel the response during the response process HOT 4
- CORS error while using open ai completions
- [Request]: Support the rest of the EventSource public APIs
- Resend request after network outage
- Can not catch network connection error during streaming data
- Resurrect repo HOT 1
- connect disconnected after change Chrome Tabs HOT 2
- Variable outside await fetchEventSource is undefined
- net::ERR_HTTP2_PROTOCOL_ERROR 200 (OK) and abortController don't work HOT 3
- fetchEventSource() repeats request indefinitely HOT 2
- Is this project abandoned by Microsoft? HOT 2
- 可以同时制作上百个标签吗
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fetch-event-source.