node-geocoder
node-geocoder copied to clipboard
Error handling for google geocoder
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
Has this been implemented? @speedazerty @nchaulet
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');
}
Hi, any updates on this?