非错误承诺拒绝以价值捕获:未定义

发布于 2025-01-20 17:16:25 字数 1267 浏览 2 评论 0原文

const validatePnr = async (pnr: string) => {
    return new Promise<void>(async (resolve, reject) => {
      try {
        setIsLoading(true);
        const url = `/api/v2/pnr/validate?stationCode=${stationCode}&outletId=${outletId}&vendorId=${vendorId}&pnr=${pnr}${
          !!currentStationInfo?.arrival ? `&eta=${currentStationInfo.arrival}` : ""
        }`;
        const data = (await CaptchaGet({ url, disableErrorToast: true })) as ApiResponse<ValidatePnrInfo>;
        if (data.status === "failure") {
          invalidPnrCb(data.message, data.result);
          reject();
        } else if (data.result.status && data.result.statusCode === 200) {
          const pnrResponse: PnrResponse = { status: data.status, result: data.result.data, message: data.message };
          validPnrCb(pnrResponse, pnr);
          resolve();
        } else {
          invalidPnrCb(data.result.statusMsg, data.result);
          reject();
        }
        setData(data.result);
      } catch (err) {
        setIsLoading(false);
        invalidPnrCb("Something went wrong. Please try again.");
        reject();
      }
    });
  };

使用值捕获非错误承诺拒绝:在 JavaScript 承诺处理哨兵中未定义,我正在正确处理拒绝,但需要您的建议我应该在代码中更改哪里?

const validatePnr = async (pnr: string) => {
    return new Promise<void>(async (resolve, reject) => {
      try {
        setIsLoading(true);
        const url = `/api/v2/pnr/validate?stationCode=${stationCode}&outletId=${outletId}&vendorId=${vendorId}&pnr=${pnr}${
          !!currentStationInfo?.arrival ? `&eta=${currentStationInfo.arrival}` : ""
        }`;
        const data = (await CaptchaGet({ url, disableErrorToast: true })) as ApiResponse<ValidatePnrInfo>;
        if (data.status === "failure") {
          invalidPnrCb(data.message, data.result);
          reject();
        } else if (data.result.status && data.result.statusCode === 200) {
          const pnrResponse: PnrResponse = { status: data.status, result: data.result.data, message: data.message };
          validPnrCb(pnrResponse, pnr);
          resolve();
        } else {
          invalidPnrCb(data.result.statusMsg, data.result);
          reject();
        }
        setData(data.result);
      } catch (err) {
        setIsLoading(false);
        invalidPnrCb("Something went wrong. Please try again.");
        reject();
      }
    });
  };

Getting Non-Error promise rejection captured with value: undefined in JavaScript promise handling sentry, I am handling rejection properly but need your suggestion where should I change in code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

您的好友蓝忘机已上羡 2025-01-27 17:16:25

reject('发生了错误')) 中传递一些内容;

它是空的(未定义),这就是您看到该错误的原因。

Pass something in reject('something went wrong'));

It's empty (undefined) that's why you see that error.

随波逐流 2025-01-27 17:16:25

如果您看到了带有“非错误异常(或承诺拒绝)捕获的键:x,y,z”

  • 错误或
  • 拒绝用普通物体的承诺。

您可以在“附加数据”部分的序列化输入中看到所讨论的非错误对象的内容。

为了更好地了解这些错误事件,我们建议根据序列化数据的内容找到普通对象的传递或抛向哨兵的位置,然后将普通对象转换为错误对象。

要忽略此错误,您可以在Sentry中添加以下配置
忽略eRERERROR:['非错误承诺拒绝捕获']

或解决此问题

if (!(error instanceof Error)) {
    error = new Error(`Non-Error rejection: ${JSON.stringify(error)}`);
  }
  Sentry.captureException(error);

,可以确保错误对象不是普通对象

If you’re seeing errors with the message “Non-Error exception (or promise rejection) captured with keys: x, y, z.”, this happens when you

  • call Sentry.captureException() with a plain object,
  • throw a plain object, or
  • reject a promise with a plain object.

You can see the contents of the non-Error object in question in the serialized entry of the “Additional Data” section.

To get better insight into these error events, we recommend finding where the plain object is being passed or thrown to Sentry based on the contents of the serialized data, and then turning the plain object into an Error object.

To Ignore this error you can add following config in sentry
ignoreErrors: ['Non-Error promise rejection captured']

Or to fix this you can try

if (!(error instanceof Error)) {
    error = new Error(`Non-Error rejection: ${JSON.stringify(error)}`);
  }
  Sentry.captureException(error);

This will ensure that the error object is not a plain object

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文