Javascript react.js firebase返回处于错误状态的响应对象
我正在围绕firebase为Javascript react.js firebase返回处于错误状态的响应对象,javascript,reactjs,firebase,Javascript,Reactjs,Firebase,我正在围绕firebase为react.js编写一个数据库包装器,如下所示: function withExistingUser( uid : string , next : any ){ const bad = [".", "#", "$", "[", "]"]; const isgood = bad.map( x => (uid.indexOf(x)===-1) ) .reduce((x,y) => x &&a
react.js
编写一个数据库包装器,如下所示:
function withExistingUser( uid : string , next : any ){
const bad = [".", "#", "$", "[", "]"];
const isgood = bad.map( x => (uid.indexOf(x)===-1) )
.reduce((x,y) => x && y, true);
if (isgood) {
const res = firebaseApp.database()
.ref('/users/' + uid).once('value')
.then( snap => {
if ( snap.val() !== undefined && snap.val() !== null )
next(snap.val())
})
return res;
} else {
// I need to return a `res` here
}
}
我需要在最后一个
else
语句中返回带有某种错误消息的响应
对象,以便我可以在以后对现有用户使用时执行然后执行和捕获
,否则我会在应用程序中遇到灾难性的失败。google搜索不会返回如何创建我想要的react.js
response对象。有什么想法吗?除非我有误解,否则你可以:
return Promise.reject({ error }):
当您.catch()