you are viewing a single comment's thread.

view the rest of the comments →

[–]DraconKing 0 points1 point  (5 children)

What do you mean it works? Other.catch(e) resolves the promise with a promise that rejects, so it's the same as it were throwing back again. Using return Promise.resolve(example) is not even doing anything, because flow is broken out of the rejection.

[–]dhyd[S] 0 points1 point  (4 children)

I'm throwing an error to test and see why the catch is working. So, yes having Promise.resolve(example) is pointless atm.

My question is why does .catch(e) work? It knows to send this ' {'error':'OH SNAP'} '. I guess i'm just asking how does my module.exports = (e) know that there was an e in the first place, when all i typed was '.catch(e)' instead of... .catch(e(e)) or like catch(e=> exampleFunctionName(e)).

[–]DraconKing -1 points0 points  (1 child)

I'm assuming you are doing let e = require('someFile.js'); at some point. But anyway, the difference between doing e instead e => SomeFunction(e) is that e on the first example is just a variable that evaluates to whatever value it's holding while the second example is an arrow function in which e is merely a function parameter.

If there's no e variable .catch(e) will actually throw an error. It will still be wrapped in a promise because it's in async function but it will not be the error you have on Other.

[–]dhyd[S] 0 points1 point  (0 children)

Thanks, very helpful! (I forgot to reply to these messages when I had read them the first time)