本文介绍了使用store.findQuery时捕获404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Embers findQuery 方法,并想知道当没有结果时如何捕获404错误?

I'm using Embers findQuery method and wonder how to catch 404 errors when there are no results?

this.store.findQuery('customer', { hasProjects: true, getArchivedProjects: archived }).then(function(customers) {
});

如果查询为空,则此内的代码然后函数不会被触发,所以我甚至不能检查客户的类型

If the query is empty, the code inside this then function doesn't get fired, so I can't even check the type of customers.

示例:

this.store.findQuery('customer', { hasProjects: true, getArchivedProjects: archived }).then(function(customers) {
  console.log('foo')
});

如果查询返回404, console.log 不被触发。

If the query returns a 404, console.log doesn't be fired.

推荐答案

findQuery函数返回一个承诺。然后,您可以向then()提供两个函数,第一个是成功路径,第二个是失败路径,例如:

The findQuery function returns a promise. You may then provide two functions to the then(), the first being the success path, the second being the failure path... for example:

this.store.findQuery('customer', { hasProjects: true, getArchivedProjects: archived }).then(function(customers) {
    console.log('foo')
}, function(error) { /* do something with error */ });

这篇关于使用store.findQuery时捕获404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 15:22