从POS 10.19.0开始,扩展回调中未处理的错误会触发错误页面,而不是静默失败。这一变更确保了商户获得更稳定且可预测的体验,并帮助开发人员主动识别问题。
为了防止对商家造成干扰并最大限度地减少意外故障,开发人员应彻底测试回调并确保所有异常都得到适当处理。
例如,此代码现在将触发错误页面:
// Before: Errors occur but do not display an error page. // POS 10.19.0 onwards: Displays an error page upon encountering an error. <Screen name="example" title="Example" onReceiveParams={(params) => mayNotExist(params)} ></Screen>一种解决方案是将逻辑包装在 try/catch 块中:
<Screen name="example" title="Example" onReceiveParams={(params) => { try { mayNotExist(params); } catch (error) { // Handle errors. } }} ></Screen>
