juliuste / sncf

SNCF API client
ISC License
27 stars 6 forks source link

Problem with request journeys #21

Closed valdu02100 closed 6 years ago

valdu02100 commented 6 years ago

Hey !

I want to test your API. I have some problem with my parameters.

See my codes :

var depart = {type: 'station', id: req.params.depart};
var arrivee = {type: 'station', id: req.params.arrivee};
var date = req.params.date;

journeys(depart, arrivee, new Date(parseInt(date,10))).then(data => {
    this.result = data;
    res.send(result);
}).catch(
    console.error
)

My parameters are : date -> 1534370400 -> Sun Jan 18 1970 19:12:50 GMT+0100 (CET) depart -> { type: 'station', id: 'FRANE' } arrivee -> { type: 'station', id: 'FRTHP' }

I got this message : TypeError: Cannot read property 'map' of undefined at journeys (/Applications/MAMP/htdocs/sncf_api/node_modules/sncf/lib/journeys.js:163:31) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7)

Some wrongs with my parameters?

Thanks for helps

juliuste commented 6 years ago

Hey @valdu02100, thank you for reporting this issue! Your date is Jan 18 1970, which is a bit too long ago for the API. Note that timestamps in JS are given in milliseconds, not seconds. Can you therefore try again with your timestamp multiplied by 1000 (1534370400000 instead of 1534370400) and let me know if this fixes your issue? 🙂

Side note: The module shouldn't throw this specific error, though, I'll have another look at it.

valdu02100 commented 6 years ago

Hi @juliuste

Thanks for your answer :

I try : req.params.date = 1534370400;

var date = new Date(req.params.date*1000);

2018-08-15T22:00:00.000Z Error : TypeError: Cannot read property 'map' of undefined at journeys (/Applications/MAMP/htdocs/sncf_api/node_modules/sncf/lib/journeys.js:163:31) at at process._tickCallback (internal/process/next_tick.js:188:7)

var date = req.params.date*1000;

1534370400000 Error: date must be a JS date object

juliuste commented 6 years ago

Should be fixed in 0.6.0. Let me know (and re-open this issue) if there are any other problems with the module, though!

Site note: The API I'm using seems to change quite often, I will probably adapt to another endpoint that is hopefully a bit more stable at some point in the near future which could bring some breaking changes to the code, just consider that when using the module in production.

valdu02100 commented 6 years ago

It works :D