Open CyrilKamal opened 1 year ago
@CyrilKamal Thank you for opening this issue. 🙏 Please check out these other resources that might help you get to a resolution in the meantime:
google-maps
tagThis is an automated message, feel free to ignore.
Kind of a workaround, but if you go to the deprecated google maps node client located here, it works perfectly fine and returns an actual error code. Here is the working code with the deprecated client
googleMapsClient.directions({origin: origin, destination: destination, waypoints:waypts, optimize:true, mode: "driving"})
.asPromise()
.then((response) => {
console.log(response)
const routeOrder = response.json.routes[0].waypoint_order;
for(let i = 0; i < reqList.length; i++){
reqList[i] = reqList[i].replaceAll(' ', '+');
}
const n = reqList.length
reorder(reqList, routeOrder, n)
console.log(reqList)
})
.catch((err) => {
console.log(err.json.status);
});
I just wanted to put this here if it happens to help you guys with debugging :)
Environment details
Steps to reproduce
I am trying to use the Google Maps Directions API in my Node.js application to get optimized routes between multiple waypoints. I haven't been able to make successful requests and receive responses using the API, and the problem is I can't debug the problem because I am getting an error that I can't get to be specific.
my client object looks like this:
and origin, destination and waypts looks like this
I've shown my whole client object with the try-catch; I suspect I don't know how to properly catch the Error because what I get is (Directions request failed due to Error).
At the GitHub for the NodeJS client for Maps API: https://github.com/googlemaps/google-maps-services-js/blob/master/README.md You can see in the quick start they want to log the error message like this e.response.data.error_message but when I try to do it that way I get console.log('Directions request failed due to ' + e.response.data.error_message);TypeError: Cannot read properties of undefined (reading 'data')
So I think there is a bug in how to get an actual helpful error code. I also tried looking into the props of the error object and went down e.config.data as that seemed the closest, but e.config.data returns undefined and has no further properties like an error_message prop.
Stack trace