graphhopper / directions-api-js-client

JavaScript client for the GraphHopper Directions API
https://graphhopper.com/api/1/examples
108 stars 85 forks source link

Better debugging #47

Closed TimoRuetten closed 5 years ago

TimoRuetten commented 5 years ago

Its a bit hard to work with the npm package because when doRequest does not work it seems that the only return error message is that there is a bad request.

I was able to make a request work. Then I changed the address data for the services of the optimized route and all I get was "Bad Request".

After checking my code I saw that the lat/lng were strings instead of floats. After changing it it worked fine.

It would be nice if the returned error would give some hints what the problem could be.

karussell commented 5 years ago

Can you provide the underlying network request that was made or a code snippet?

TimoRuetten commented 5 years ago

Of course. I am using your graphhopper-js-api-client client. An example request looks like this:

const ghRouting = new GraphHopperNotOptimization({
      key,
      vehicle: 'car',
      elevation: false,
    });
ghRouting.doRequest({
          vehicles: [vehicle],
         // ...
          vehicle_types: [{
            type_id: 'vehicle_type_1',
            profile: 'car',
          }],
          services,
        }).then(() => {}).catch(() => {});

The catch always return just "Bad Request" when something seems to be wrong. It was a bit hard to make everything work without exactly knowing what the matter was.

karussell commented 5 years ago

Ok, thanks! This should be fixed now, will be uploaded soonish.

For future reference this is the way to query the Route Optimization API:

const ghRO = new GraphHopper.Optimization({key: "your_key"});
ghRO.doRequest(requestJsonWithSyntaxError).
then( function(json){console.log(json)}).
catch(function(json){console.log(json)});
boldtrn commented 5 years ago

0.11.1 was published :)

karussell commented 5 years ago

Great - thanks!

TimoRuetten commented 5 years ago

Thanks for your fast response and making the package better for debugging when something went wrong :)

Cheers