Last active
February 2, 2022 12:34
-
-
Save munkacsitomi/aeefd370ae7784fc4ccb53f1f0c322d2 to your computer and use it in GitHub Desktop.
Multiple error handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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