Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw on 402 error #145

Open
mlucool opened this issue Jan 16, 2016 · 2 comments
Open

Throw on 402 error #145

mlucool opened this issue Jan 16, 2016 · 2 comments

Comments

@mlucool
Copy link
Contributor

mlucool commented Jan 16, 2016

Hi,

When I go over my API limit for opencage it throws: "Error: Response status code is 402" from \lib\httpadapter\httpadapter.js:58:25

This is acceptable, but there is no way to catch it. When I go over the Google API limit, the error it is thrown in a catchable manner and I see output: "Error: Error: Status is OVER_QUERY_LIMIT. You have exceeded your rate-limit for this API."

Below is an example to reproduce these two cases. Google is how it should work, while opencage I believe has a bug.

import 'babel-polyfill';

import co from 'co';
import NodeGeocoder from 'node-geocoder';
const geocoder = NodeGeocoder('opencage', 'https', {apiKey: 'MYAPYKEYHERE'});
//const geocoder = NodeGeocoder('google');

co(function *() {
    for (let i = 0; i < 5000; ++i) {
        try {
            const res = yield geocoder.reverse({lat: '40.71', lon: '-74.0'});
            console.log(res)
        } catch (err) {
            console.log('Error: ' + err);
        }
    }
});
@nchaulet
Copy link
Owner

I thinks we could have a generic QuotaExcedeed error.

@mlucool
Copy link
Contributor Author

mlucool commented Jan 18, 2016

That would be helpful. A starting set of generic errors could include:
QuotaExceeded, RateExceeced, InvalidAPIKey, InvalidRequest, ServerError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants