Skip to content

Instantly share code, notes, and snippets.

@munkacsitomi
Last active February 2, 2022 12:34
Show Gist options
  • Save munkacsitomi/aeefd370ae7784fc4ccb53f1f0c322d2 to your computer and use it in GitHub Desktop.
Save munkacsitomi/aeefd370ae7784fc4ccb53f1f0c322d2 to your computer and use it in GitHub Desktop.
Multiple error handling
async send() {
let success = false;
try {
const { data } = await httpPost();
success = !data?.errors || data.errors.length === 0;
} catch(e) {
// handled below because failure can happen on two occasions
// 1. httpPost fails
// 2. the call was successful but the BE gives back error
throw e;
}
if (success) {
toast.show('Success');
} else {
toast.show('Error');
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment