Sign in
Log inSign up
Bibek Kakati

176 likes

·

1.8K reads

12 comments

Ayodele Samuel Adebayo
Ayodele Samuel Adebayo
Jun 19, 2021

🔥🔥🔥🔥

1
·
Shubham Rai
Shubham Rai
Jun 21, 2021

I like this way to handle error in JS

1
·
·2 replies
Bibek Kakati
Bibek Kakati
Author
·Jun 21, 2021

I'm glad that you liked it.

Try to use this pattern in your project.

2
·
Shubham Rai
Shubham Rai
Jun 21, 2021

Yes definitely I will try to use this pattern in my project. This will make my code readable too

1
·
Adriano Luz
Adriano Luz
Jun 23, 2021

Would love to read more about the advantages and disadvantages of the "go style" error handling.

1
·
·1 reply
Bibek Kakati
Bibek Kakati
Author
·Jun 23, 2021

There is no major advantage and disadvantage with this pattern.

1
·
Andrew Baisden
Andrew Baisden
Jun 24, 2021

Interesting take on it Bibek Kakati 👏

1
·
·1 reply
Bibek Kakati
Bibek Kakati
Author
·Jun 24, 2021

Thank you Andrew Baisden

1
·
Niranjan Borawake
Niranjan Borawake
Jun 25, 2021

Nice one. Reminds of Error-first callback in NodeJs.

1
·
·1 reply
Bibek Kakati
Bibek Kakati
Author
·Jun 25, 2021

Thank you 😊

1
·
Zsolt Gömöri
Zsolt Gömöri
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
Bibek Kakati
Bibek Kakati
Author
·Jul 1, 2021

Yeah. We can implement like this too.

2
·