node-geocoder icon indicating copy to clipboard operation
node-geocoder copied to clipboard

Throw on 402 error

Open mlucool opened this issue 9 years ago • 2 comments

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);
        }
    }
});

mlucool avatar Jan 16 '16 04:01 mlucool

I thinks we could have a generic QuotaExcedeed error.

nchaulet avatar Jan 18 '16 15:01 nchaulet

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

mlucool avatar Jan 18 '16 15:01 mlucool