Skip to content

Instantly share code, notes, and snippets.

@josephschmitt
Created January 31, 2020 16:12
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 josephschmitt/176791755c54bb15a7352fcf254776af to your computer and use it in GitHub Desktop.
Save josephschmitt/176791755c54bb15a7352fcf254776af to your computer and use it in GitHub Desktop.
// By default, use a try/catch with async await
try {
await someRemoteAction();
} catch (e) {
console.error(e);
}
// If you need to store the result of an async/await AND you want the catch to be a specific value...
const myResult = await someRemoteAction().then(() => 'some-value').catch(() => 'some-error-value');
// myResult will equal 'some-value' on success, but 'some-error-value' on error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment