175 likes
·
1.5K reads
12 comments
·Jun 19, 2021
Jun 19, 2021
🔥🔥🔥🔥
1
·
·Jun 21, 2021
Jun 21, 2021
I like this way to handle error in JS
1
·
·2 replies
Author
·Jun 21, 2021
I'm glad that you liked it.
Try to use this pattern in your project.
2
·
·Jun 21, 2021
Jun 21, 2021
Yes definitely I will try to use this pattern in my project. This will make my code readable too
1
·
·Jun 23, 2021
Jun 23, 2021
Would love to read more about the advantages and disadvantages of the "go style" error handling.
1
·
·1 reply
Author
·Jun 23, 2021
There is no major advantage and disadvantage with this pattern.
1
·
·Jun 24, 2021
Jun 24, 2021
Interesting take on it Bibek Kakati 👏
1
·
·1 reply
Author
·Jun 24, 2021
Thank you Andrew Baisden
1
·
·Jun 25, 2021
Jun 25, 2021
Nice one. Reminds of Error-first callback in NodeJs.
1
·
·1 reply
Author
·Jun 25, 2021
Thank you 😊
1
·
·Jul 1, 2021
Jul 1, 2021
Nice, I dig it! Thanks Bibek Kakati!
I’d like to chime in with a minor yet potential improvement.
const getData = async () => {
try {
const result = await methodCall();
return { result };
} catch(error) {
return { error };
}
}
const { result, error } = getData();
if (error) {
// …
}
IMO returning an object (and destructuring both result
and error
) is way more readable & explicit.
1
·
·1 reply
Author
·Jul 1, 2021
Yeah. We can implement like this too.
2
·