3 ms·
Okay, that's a fair counter-argument. My gut feeling is that's possibly one catch to many and as much as possible I'd want to try to merge the two catches/unify
by WorldMaker 11y ago
Okay, that's a fair counter-argument. My gut feeling is that's possibly one catch to many and as much as possible I'd want to try to merge the two catches/unifying the error response logic.
Another idea is that you could reformat to a "parade" try/catch by adding returns to the catch:
try {
const response = await fetch('./api.json')
} catch (fetchError) {
console.warn('this is not cool')
return // Exit
}
try {
const json = await response.json();
console.log('YAY! JSON!', json);
} catch (jsonParseError) {
alert('damn it!');
}
Obviously you'd need to move any code you'd want to run regardless of error up into the parent function or out into a wrapper function.