简体   繁体   English

mockServiceWorker.js:129 [MSW] 从“POST https://....”请求中捕获异常(TypeError:无法获取)

[英]mockServiceWorker.js:129 [MSW] Caught an exception from the "POST https:// ...."request (TypeError: Failed to fetch)

I have a react web app where i'm mocking the api requests through MSW.我有一个反应 web 应用程序,我是 mocking api 通过 MSW 请求。 I'm now trying to integrate a third party error reporting service like sentry.我现在正在尝试集成第三方错误报告服务,如哨兵。 The client calls sentry's endpoint whenever an error happens, so I need the msw to bypass this call.每当发生错误时,客户端都会调用哨兵的端点,因此我需要 msw 绕过此调用。 The problem now is that MSW is interfeering somehow and makes the call to never reach sentry's endpoint.现在的问题是 MSW 以某种方式进行干扰,并使调用永远不会到达哨兵的端点。 I know this cause disabling MSW allowed the call to reach it perfectly.我知道这个原因禁用 MSW 允许呼叫完美地到达它。

The url sentry's client is trying to reach: url 哨兵的客户端试图到达:

https://token.ingest.sentry.io/api/foo?bar=mee

How I start MSW (shouldn't this part do the trick?)我如何开始 MSW(这部分不应该解决问题吗?)

worker.start({ onUnhandledRequest: 'bypass' })

Error I get我得到的错误

mockServiceWorker.js:129 [MSW] Caught an exception from the "POST https://________________________.ingest.sentry.io/api/_____________/envelope/?sentry_key=__________________________________&sentry_version=7&sentry_client=sentry.javascript.browser%2F7.21.1" request (TypeError: Failed to fetch). This is probably not a problem with Mock Service Worker. There is likely an additional logging output above.
(anonymous) @ mockServiceWorker.js:129
Promise.catch (async)
(anonymous) @ mockServiceWorker.js:118
fetch.ts:35          POST https://________________________.ingest.sentry.io/api/_____________/envelope/?sentry_key=__________________________________&sentry_version=7&sentry_client=sentry.javascript.browser%2F7.21.1 net::ERR_FAILED

In MSW version 4, req.passthrough() might be what you are looking for:在 MSW 版本 4 中, req.passthrough()可能是您正在寻找的:

rest.post('/api/foo', (req, res, ctx) => {
    return req.passthrough();
});

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

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