【发布时间】:2021-05-26 06:29:45
【问题描述】:
我正在开发一个使用 Ember 数据的 Ember 应用程序。我们主要使用 Rails 和 Postgres 作为后端,但一小部分数据存储在 WordPress 后端。 WordPress 正在 wp.example.com 上运行。
Ember Data 设置为可与 Rails 和 WordPress 后端一起使用,因此我可以执行以下操作:
// Get WordPress category by slug
this.store.query('wordpress/category', { slug }).then((models) => {
// Leave page if no category was found
if (typeof models.get('firstObject') == 'undefined') this.transitionTo('backupRoute');
return models.get('firstObject');
});
现在我想知道如果wp 子域处于脱机状态,我该如何捕捉错误。
当我更改 WordPress 后端 URL 时(我不确定这是否是模拟失败的最佳方法),几秒钟后我在 Chrome DevTools 中收到 (failed)net::ERR_NAME_NOT_RESOLVED 并且 Ember 显示错误 500。相反,我会喜欢捕捉网络错误并做一些有用的事情,在本例中是重定向。
有没有办法捕捉这些错误?添加一个简单的catch() 会完全破坏页面。当有一个未决的请求时,它会保持白色约两分钟,然后显示 502 Bad Gateway。我也在日志中得到了这个:
my_service_1 | (node:1) UnhandledPromiseRejectionWarning: [object Object]
my_service_1 | (node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 13)
【问题讨论】:
标签: javascript node.js ember.js ember-data