You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So to make our code more concise, we implement a module-wide error function catch. It really reduces and cleans up the code, especially when you have 20 on a page:
But this has unintended behavior because the "then" is always called even when a reject() is fired.
test('a').catch(err=>{console.log('error '+err.message)}).then(res=>{console.log(res)});functiontest(item){returnnewPromise((resolve,reject)=>{if(typeofitem==='number'){resolve(item);}else{reject(newError('item not number'));}});}
which yields:
error item not number
undefined
The "undefined" means the "then" was called. Is it crazy to put the catch before the then? Is there another way to accomplish this without putting the catch last? Thanks.
The text was updated successfully, but these errors were encountered:
So to make our code more concise, we implement a module-wide error function catch. It really reduces and cleans up the code, especially when you have 20 on a page:
But this has unintended behavior because the "then" is always called even when a reject() is fired.
which yields:
error item not number
undefined
The "undefined" means the "then" was called. Is it crazy to put the catch before the then? Is there another way to accomplish this without putting the catch last? Thanks.
The text was updated successfully, but these errors were encountered: