【问题标题】:Why am I getting an empty body response for user feedback in sentry?为什么我在哨兵中收到用户反馈的空白响应?
【发布时间】:2018-07-05 03:58:23
【问题描述】:

我正在使用 ReactJS 为 Sentry 设置用户反馈。

我初始化它:

import Raven from 'raven-js';

Raven.config(https://#########@sentry.io/#######, {
  environment: "development",
}).install();

并在ErrorBoundary(https://reactjs.org/docs/error-boundaries.html) 概念中使用componentDidCatch 来显示报告对话框。

componentDidCatch(error, info) {
    this.setState({ hasError: true });
    Raven.captureException(error, { extra: info });
    Raven.showReportDialog();
}

当我提交对话时,网络向我显示一个 POST 请求,其中包含 200 响应和一个确认对话成功。但是,正文是空的,并且在我的哨兵帐户的项目的用户反馈部分中看不到提交的表单。

该行为与此站点上的情况相同:https://wiggly-power.glitch.me/

【问题讨论】:

  • 两年后仍然遇到这个问题。这是一个奇怪的问题,因为它前几天还在工作。我本可以发誓我必须启用一些选项才能做到这一点。如果我找到解决方案,我会尽力跟进。

标签: javascript reactjs sentry raven


【解决方案1】:

我认为你应该只调用函数componentDidCatch(..)、setState(..)等来检查这种情况。不要试图在这个函数中做业务流程。

componentDidCatch(error, info) {
    this.setState({ hasError: true });
    Raven.captureException(error, { extra: info });
}

查看this 并尝试在 render() 方法中调用这些函数:

if (this.state.hasError) {
 Raven.showReportDialog();
}

【讨论】: