Comments (7)
@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.
Hi @JohnDoePBabu I'm assigning this to you...
from buymeacoffee.js.
@warengonzaga We can do one of the below
- 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));
});
- 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
- 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
- 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.
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.
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.
Hi @JohnDoePBabu,
I would prefer to throw an error message instead of empty array.
from buymeacoffee.js.
All good closing this issue with merge #18
from buymeacoffee.js.
Related Issues (20)
- maintain with Lerna HOT 1
- update README file HOT 1
- migrate to webpack HOT 11
- no data return on request HOT 17
- migrate to Yarn from NPM
- add huntr.dev badge
- dedicated landing page HOT 7
- apply for subdomain to js.org HOT 3
- sponsor and supporter badge broken images
- improve opengraph for the landing page HOT 7
- 404 not found page HOT 5
- new favicon for the website (and the project) HOT 8
- replace repo banner HOT 18
- landing page improvements HOT 12
- migrate to parcel HOT 1
- add options for subscriptions HOT 2
- migrate to typescript HOT 6
- update bmc badge url HOT 1
- move the homepage to orphan branch HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from buymeacoffee.js.