【问题标题】:mockServiceWorker.js:129 [MSW] Caught an exception from the "POST https:// ...."request (TypeError: Failed to fetch)mockServiceWorker.js:129 [MSW] 从“POST https:// ....”请求中捕获异常(TypeError:获取失败)
【发布时间】:2022-11-30 06:05:26
【问题描述】:

我有一个反应网络应用程序,我在其中通过 MSW 模拟 api 请求。我现在正在尝试集成第三方错误报告服务,如哨兵。每当发生错误时,客户端都会调用哨兵的端点,因此我需要 msw 绕过此调用。现在的问题是 MSW 以某种方式进行干扰,并使调用永远不会到达哨兵的端点。我知道这个原因禁用 MSW 允许呼叫完美地到达它。

url 哨兵的客户端正试图到达:

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

我如何开始 MSW(这部分不应该解决问题吗?)

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

我得到的错误

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

【问题讨论】:

    标签: javascript vite sentry amazon-mws


    【解决方案1】:

    在 MSW 版本 4 中,req.passthrough() 可能是您要查找的内容:

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

    【讨论】:

    • 抱歉,这不起作用
    猜你喜欢
    • 2013-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-21
    • 2014-01-20
    • 1970-01-01
    • 2021-03-21
    • 2021-12-06
    相关资源
    最近更新 更多