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

Error handling for google geocoder

Open speedazerty opened this issue 8 years ago • 3 comments

When google API sends a response with a 400 status code (or any non 200 codes), It is not possible to see the details of the error on the callback of the geocode function.

example :

geocode('', function(err, result){
  // err does not contain error details from google like error_message 'INVALID_request'
  // it is not contained into result neither
})

Test endpoint : http://maps.googleapis.com/maps/api/geocode/json?address=

P.S. : I can send a pull request to solve it

speedazerty avatar Jul 28 '16 15:07 speedazerty

Has this been implemented? @speedazerty @nchaulet

Shane-Neeley avatar Dec 19 '17 20:12 Shane-Neeley

Hey,

You could try this. Seems to be working for me, you will need to modify the res.flash as thas a plugin Im using

        if (err || data.status === 'ZERO_RESULTS') {
            req.flash('error', 'Invalid address, try typing a new address');
            return res.redirect('back');
        }

        if (err || data.status === 'REQUEST_DENIED') {
            req.flash('error', 'Something Is Wrong Your Request Was Denied');
            return res.redirect('back');
        }

        if (err || data.status === 'OVER_QUERY_LIMIT') {
            req.flash('error', 'All Requests Used Up');
            return res.redirect('back');
        }

AlexMachin1997 avatar Sep 04 '18 17:09 AlexMachin1997

Hi, any updates on this?

bakasmarius avatar Jun 15 '20 08:06 bakasmarius