Comments (5)
I'm not very familiar with Etherscan API response format, but my guess would be that each section of the API (or a group of sections) have different response format (which leads to an issues like this).
My suggestion would be to actually pass the module
and action
variables to the getRequest
function and to handle the response parsing according to the module/action.
Please, consider the following example:
function getRequest(query, module, action) {
return client.get('/api?' + query)
.then(response => {
const data = response.data;
switch (module) {
case 'account':
/**
{
"status": "0",
"message": "No transactions found",
"result": []
}
*/
if (0 === data.status) {
return Promise.reject(new Error(data.message));
} else {
return data.result;
}
default:
// ... default (common) handling logic
return data;
}
})
// Probably this catch is not required at all
.catch(error => {
if (error instanceof Error) {
reject(error); // passing as is
} else {
reject(new Error(error)); // wrapping in error
}
})
;
}
It's not a final implementation, but a very much close to it. Also, notice that your implementation could be simplified. No need to call new Promise()
because axios already returns a promise.
from etherscan-api.
Throw me a PR, Ill merge all sane code ;)
I guess I would remark if statements when looking at what you propose.
There was a change regarding error reporting and surely this is my bad, i was just to stubborn to follow the specs. I have some time in the 2019 and will put this in.
I might consider using this as a starter for mocks.
Thanks for your time.
from etherscan-api.
Hold your horses with a PR -.....
I guess I will write some swagger definition and re-release the mod as a open api export. This will take some time, but it will tackle the issue of apis giving different responses in a well defined way. + focus is on testing the code and not writing boiler plate stuff.
from etherscan-api.
I guess we have to do #43
from etherscan-api.
can I close this? ;) Not sure atm. If not, there is time to improve more
from etherscan-api.
Related Issues (20)
- Support arbitrum with etherscan-api HOT 1
- No typings for Typescript projects HOT 1
- Support for getting verified contract source code HOT 2
- Support also other chains using an explorer compatible with etherscan HOT 3
- replace querystring HOT 4
- Which function in account can get the list of ERC1155? HOT 1
- Add snowtrace for avalanche mainnet and testnet (fuji)
- Is typecript project on the way? HOT 3
- Goerli chain selection fails and uses the mainnet URL HOT 1
- Goerli added but no new package published to npm HOT 1
- Mmm
- 0x6Bb39276bA115B89F97433BF12307CcBA2d575Dc HOT 1
- Beta of new version
- ιΎζ₯θΆ ζΆ
- Incorrect balance being returned for api.account.balance call
- Manny27nyc
- Gett list of transactions by address HOT 2
- 1db3b1c5cae8e967300c3ce755aa90efaefd091e HOT 1
- [Enhancement] Hope to support customized httpsagent config for axios HOT 3
- Incorrect result of txlistinternal method HOT 2
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 etherscan-api.