Skip to content

Instantly share code, notes, and snippets.

@Infinitay

Infinitay/tph.js Secret

Created March 4, 2020 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Infinitay/bfb1feac73b75a034997d6b0b16b1bab to your computer and use it in GitHub Desktop.
Save Infinitay/bfb1feac73b75a034997d6b0b16b1bab to your computer and use it in GitHub Desktop.
The Programming House Discord Support Post
// How come the following snippet's `error` when caught is `undefined`:
app.on('ready', () => {
Promise.all([......]).then(async () => {
...
const eventRootFolderId = folderIdRegex.exec(event.link)[1];
...
}).catch(error => logger.error(error)); // Undefined
});
// But when I try and catch, and then return the caught error, it is then caught and no longer `undefined`.
app.on('ready', () => {
Promise.all([......]).then(async () => {
...
try {
const eventRootFolderId = folderIdRegex.exec(event.link)[1];
} catch (innerError) {
return innerError; // If I change this to something like logger.error(innerError), it also treats innerError to be null, but not when I return it
}
}).catch(error => logger.error(error)); // No longer undefined
});
// I was under the assumption that in the first snippet, or any catch block, it catches any error, therefore I don't need to try...catch within the anonymous async function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment