GithubHelp home page GithubHelp logo

Comments (7)

warengonzaga avatar warengonzaga commented on May 27, 2024

@JohnDoePBabu what is your best approach for handling error? I didn't add the error handling while making the project since I want to understand how BMC API works. Do you have any suggestion since we are going to use GOT might has better error handling than request.

from buymeacoffee.js.

warengonzaga avatar warengonzaga commented on May 27, 2024

Hi @JohnDoePBabu I'm assigning this to you...

from buymeacoffee.js.

JohnDoePBabu avatar JohnDoePBabu commented on May 27, 2024

@warengonzaga We can do one of the below

  1. Catch error from Axios and pass the error as the first callback
        try {
            const response = await requester.get(path, {
                headers: {
                    Authorization: 'Bearer ' + this.access_token,
                }
            });
            callback(null, response.data); 
        } catch (err) {
            callback(err);
        }

Pros:

  • With callback and Node JS, error first is the real recognized approach.

Cons:

  • For people currently using the library, this will be a very big breaking change.
    if they are currently using the module as
coffee.Subscriptions((data) => {
    console.log(JSON.stringify(data));
  });

They will have to change to

 if (err) // do something with error
 else console.log(JSON.stringify(data));
  });
  1. Catch error from Axios and pass the error as a second callback
 if (err) // do something with error
 else console.log(JSON.stringify(data));
  });

Pros:

  • Backward compatible with the previous version of BMC JS. No breaking change for current users.
    Cons:
  • Against Node JS convention.
  • counter-intuitive for future users
  1. Move to Promise style of handling error by rejecting

        try {
            const subcriptions = await coffee.Subscriptions();
        } catch (err) {
            // do something with error
        }

Pros: cleaner than callback
Cons: Again breaking change

  1. Support both callback and promise
    Check if the user has sent a function as a second argument if so return callback else use a promise.
    Again for the callback version, we will have to decide if we want option 1 or option 2.
    So the user can do both
coffee.Subscriptions((err, data) => {
 if (err) // do something with error
 else console.log(JSON.stringify(data));
  });

and ...

        try {
            const subcriptions = await coffee.Subscriptions();
        } catch (err) {
            // do something with error
        }

from buymeacoffee.js.

warengonzaga avatar warengonzaga commented on May 27, 2024

What do you think is better @JohnDoePBabu? and more standard?
What I see your option number 3 is more okay to me. Breaking changes is natural since we are planning to release the v2.
We need clear documentation once these changes implemented so they can easily adapt to the latest version.

from buymeacoffee.js.

JohnDoePBabu avatar JohnDoePBabu commented on May 27, 2024

Hi @warengonzaga,

I noticed that when there is no data, eg: no supporters, BMC API sends a 200 response with an error in the response body.
such as
{ "error": "No subscriptions" }
Shall we implement it the same way or do you prefer to

  • send an empty array
  • throw an error

from buymeacoffee.js.

warengonzaga avatar warengonzaga commented on May 27, 2024

Hi @JohnDoePBabu,

I would prefer to throw an error message instead of empty array.

from buymeacoffee.js.

warengonzaga avatar warengonzaga commented on May 27, 2024

All good closing this issue with merge #18

from buymeacoffee.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.