非错误承诺拒绝以价值捕获:未定义
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
reject('发生了错误'))
中传递一些内容;它是空的(
未定义
),这就是您看到该错误的原因。Pass something in
reject('something went wrong'))
;It's empty (
undefined
) that's why you see that error.如果您看到了带有“非错误异常(或承诺拒绝)捕获的键:x,y,z”
您可以在“附加数据”部分的序列化输入中看到所讨论的非错误对象的内容。
为了更好地了解这些错误事件,我们建议根据序列化数据的内容找到普通对象的传递或抛向哨兵的位置,然后将普通对象转换为错误对象。
要忽略此错误,您可以在Sentry中添加以下配置
忽略eRERERROR:['非错误承诺拒绝捕获']
或解决此问题
,可以确保错误对象不是普通对象
If you’re seeing errors with the message “Non-Error exception (or promise rejection) captured with keys: x, y, z.”, this happens when you
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
This will ensure that the error object is not a plain object