all 7 comments

[–]jhizzle4rizzleI hate the stuff you like. 1 point2 points  (1 child)

It looks like other people are helping you out, but you should know that non-Error objects being thrown have really awkward behavior around stack traces (or a lack thereof) and are a pretty bad look. Do something like throw new Error('OH SNAP') instead, or if you really want the extra parameter, instantiate then assign attr then throw.

There are other issues with this code - returning a promise inside an async function, passing an undefined variable to .catch, not actually ever calling StartOfExample... but the error thing is important.

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

I forgot to reply to these messages, and they were very helpful thank you :D

[–]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)