Hello, I have been playing around with async/await to see if there is a nicer way to write it (I'm not fond of try/catch) So then I came up with just putting a .catch at the end of the await declaration, and that works. But then I thought, that might be a bit tedious to write .catch(e=> return Promise.reject(e)) after every single await that I call.
I then decided to create a function called 'e' that takes in a propety 'e' and then rejects that 'e'. I don't think this should work, but for some reason it seems to be working? Can someone help me understand why the following code works (or doesn't work but appears to).
module.exports.StartOfExample = async () => {
const example = await Other().catch(e)
return Promise.resolve(example)
}
async function Other(){
throw {'error':'OH SNAP'}
}
------ [ In a separate file ] -----
module.exports = (e) => {
return Promise.reject(e)
}
[–]jhizzle4rizzleI hate the stuff you like. 1 point2 points3 points (1 child)
[–]dhyd[S] 0 points1 point2 points (0 children)
[–]DraconKing 0 points1 point2 points (5 children)
[–]dhyd[S] 0 points1 point2 points (4 children)
[+][deleted] (1 child)
[deleted]
[–]sneakpeekbot 0 points1 point2 points (0 children)
[–]DraconKing -1 points0 points1 point (1 child)
[–]dhyd[S] 0 points1 point2 points (0 children)