草庐IT

promised-mongo

全部标签

javascript - 你能 "plug in"到 Chrome 中未处理的 Promise 拒绝吗?

这个问题在这里已经有了答案:Catchallunhandledjavascriptpromiserejections(4个答案)关闭7年前。不久前,v8获得了capabilitytodetectPromisesthatarerejectedbuthavenohandlersattached(commit)。这作为一个很好的控制台错误出现在Chrome中,当您输入错误或忘记附加处理程序时特别有用:我想添加一个处理程序来在发生这种情况时采取一些行动(例如,向错误报告服务报告),类似于未捕获的异常模式:window.addEventListener("error",handler);或者,我

javascript - 仅捕获 "unhandled" promise 的全局错误处理程序

我的Angular应用程序有一个全局错误处理程序,它被编写为$http拦截器,但我想更进一步。我想要的是对于每个失败(被拒绝)的$http调用,promise的任何“链接”消费者应该首先尝试解决错误,如果它仍然未解决(未被捕获)),然后我希望全局错误处理程序接管。用例是,我的全局错误处理程序在屏幕顶部显示一个咆哮的“警告框”。但是我有几个弹出的模式,我在那里明确地处理错误,在模式本身中显示一条错误消息。所以,本质上,这个模态Controller应该将被拒绝的promise标记为“已处理”。但是由于拦截器似乎总是第一个在出现$http错误时运行,所以我想不出一种方法来做到这一点。这是我的

javascript - 吞下消息 : Error: Uncaught (in promise): [object Undefined]

我的登录组件在被有关promise中undefinedobject的错误消息删除之前短暂显示。这是promise定义:staticinit():Promise{KeycloakClientService.auth.loggedIn=false;returnnewPromise((resolve,reject)=>{constkeycloakConfig={url:environment.KEYCLOAK_URL,realm:environment.KEYCLOAK_REALM,clientId:environment.KEYCLOAK_CLIENTID,'ssl-required':'

javascript - Firebase 推送 promise 永远无法解决

我正在尝试从我的ReactNative应用程序中保存一个对象。请查看下面的代码片段。const{currentUser}=firebase.auth();firebase.database().ref(`/users/${currentUser.uid}/employees`).push({name,phone,shift}).then(()=>{console.log('SavetoFirebasewassuccessful');}).catch((error)=>{console.log(error);});但在Firebase控制台中,我什么也看不到。我很惊讶then和catch

javascript - 如何使用 jest 使用 Promise.all 设置多次提取测试

我正在使用jest进行测试。我正在使用react和redux,我有这个Action:functiongetData(id,notify){return(dispatch,...)=>{dispatch(anotherFunction());Promise.all(['resource1','resource2','resource3']).then(([response1,response2,response3])=>{//...handleresponses}).catch(error=>{dispatch(handleError(error));}};}我一直在Jest文档中寻找如

javascript - AngularJS 中的 promise 是否捕获每个异常/错误?

我在工作中继承了一个代码库,其中包含以下模式的十几个示例:varpromise=null;try{promise=backendService.getResults(input);}catch(exception){console.err(exception);}if(promise!==null){promise.then(function(response){//dostuff}).catch(function(error){console.err(error);});}其中backendService是一个Angular服务,它又通过$http调用REST服务。所以这是我的问题:

javascript - 使用 errorCallback 突破 Promise "then"链

--编辑--我最近遇到了一件关于promises的奇怪事情,但我想这可能是因为它违反了promises的哲学。考虑以下代码://AssumingAuthisjustasimplelibdoinghttprequestswithpromisesAuth.signup().then(succCall,errCall).then(loginSucc,loginErr)//MycallbacksherefunctionsuccCall(){//OK,sendsecondpromiseconsole.log('succCall');returnAuth.login();}functionerrC

Javascript:Promises + this

这个问题在这里已经有了答案:Howdoesthe"this"keywordwork,andwhenshoulditbeused?(22个答案)关闭6年前。考虑以下代码:foo:function(){varself=this;varp1=p2=someFunctionThatReturnsAPromise();Promise.all([p1,p2]).then(self.bar);}bar:function(promises){varself=this;console.log(self);}输出:undefined但如果我改为执行以下操作:foo:function(){varself=t

javascript - promise 解决后如何从 Promise 对象中获取值

请注意这是一个人为的例子。functionlongFunc(){vardeferred=$.Deferred();setTimeout(function(){console.log("longfunccompleted");deferred.resolve("hello");},3000);returndeferred.promise();}functionshortAfterLongFunc(x){console.log('shortfunccompletedwithvalue:'+x);return{a:x};}processFurther(longFunc().then(shor

javascript - Angular - 绑定(bind)到返回 promise 的函数

我是Angular的新手,我很难弄清楚这个问题的根源。我正在编写一个单页应用程序,并且正在处理身份验证部分。我有一个名为“sessionService”的服务,我希望能够在整个应用程序中使用它来确定用户是否登录。如果我这样做很简单:...service('sessionService',function(...){/*...snip...*/this.isLoggedIn=function(){returnthis.authenticated;};});其中“已验证”仅供服务私有(private)。但是,如果我刷新页面,就会分崩离析。所以,我的想法是做这样的事情:/*...snip..