public-transport / hafas-client

JavaScript client for HAFAS public transport APIs.
ISC License
272 stars 54 forks source link

Exception when product is null #203

Closed gaudes closed 3 years ago

gaudes commented 3 years ago

Hello,

I get the following exception:

TypeError: unknown product 
  File "/opt/iobroker/node_modules/hafas-client/format/products-filter.js", line 22, col 34, in Object.formatProductsFilter
    if (!byProduct[product]) throw new TypeError('unknown product ' + product)
  File "/opt/iobroker/node_modules/hafas-client/index.js", line 161, col 12, in Object.journeys
    profile.formatProductsFilter({profile}, opt.products || {})
  File "/opt/iobroker/node_modules/iobroker.fahrplan/lib/route.js", line 88, col 45, in fRoute.getRoute
    aRouteResult = await this.helper.hClient.journeys(this.StationFrom.id.toString(), this.StationTo.id.toString(), RouteOptions.returnRouteOptions());
  File "/opt/iobroker/node_modules/iobroker.fahrplan/main.js", line 255, col 18, in Fahrplan.getRoute
    await Route.getRoute(RouteOptions);
  File "internal/process/task_queues.js", line 97, col 5, in processTicksAndRejections

Product seems to be null.

gaudes commented 3 years ago

Is it possible that this error occurs when there is walking distance:

image

derhuerst commented 3 years ago

I can see that you're using iobroker, probably with some plugin. But which endpoint/profile are you using?

derhuerst commented 3 years ago

I managed to reproduce that journey using the Deutsche Bahn profile; hafas-client successfully queries & parses it:

{
    "type": "journey",
    "legs": [
        {
            "origin": {
                "type": "stop",
                "id": "8007310",
                "name": "Bahlingen Riedlen",
                "location": {
                    "type": "location",
                    "id": "8007310",
                    "latitude": 48.121324,
                    "longitude": 7.743757
                },
                "products": {
                    "nationalExpress": false,
                    "national": false,
                    "regionalExp": false,
                    "regional": true,
                    "suburban": true,
                    "bus": false,
                    "ferry": false,
                    "subway": false,
                    "tram": false,
                    "taxi": false
                }
            },
            "destination": {
                "type": "stop",
                "id": "8007294",
                "name": "Nimburg(Baden)",
                "location": {
                    "type": "location",
                    "id": "8007294",
                    "latitude": 48.105342,
                    "longitude": 7.760271
                },
                "products": {
                    "nationalExpress": false,
                    "national": false,
                    "regionalExp": false,
                    "regional": true,
                    "suburban": true,
                    "bus": true,
                    "ferry": false,
                    "subway": false,
                    "tram": false,
                    "taxi": true
                }
            },
            "departure": "2020-12-12T23:11:00+01:00",
            "plannedDeparture": "2020-12-12T23:11:00+01:00",
            "departureDelay": null,
            "arrival": "2020-12-12T23:13:00+01:00",
            "plannedArrival": "2020-12-12T23:13:00+01:00",
            "arrivalDelay": null,
            "reachable": true,
            "tripId": "1|287452|0|80|12122020",
            "line": {
                "type": "line",
                "id": "4-8006c6-12",
                "fahrtNr": "9687",
                "name": "S 12",
                "public": true,
                "adminCode": "8006C6",
                "mode": "train",
                "product": "suburban",
                "operator": {
                    "type": "operator",
                    "id": "db-regio-ag-baden-wurttemberg",
                    "name": "DB Regio AG Baden-Württemberg"
                }
            },
            "direction": "Eichstetten am Kaiserstuhl",
            "arrivalPlatform": null,
            "plannedArrivalPlatform": null,
            "departurePlatform": null,
            "plannedDeparturePlatform": null
        },
        {
            "origin": {
                "type": "stop",
                "id": "8007294",
                "name": "Nimburg(Baden)",
                "location": {
                    "type": "location",
                    "id": "8007294",
                    "latitude": 48.105342,
                    "longitude": 7.760271
                },
                "products": {
                    "nationalExpress": false,
                    "national": false,
                    "regionalExp": false,
                    "regional": true,
                    "suburban": true,
                    "bus": true,
                    "ferry": false,
                    "subway": false,
                    "tram": false,
                    "taxi": true
                }
            },
            "destination": {
                "type": "stop",
                "id": "503550",
                "name": "Nimburg Bahnhof, Teningen",
                "location": {
                    "type": "location",
                    "id": "503550",
                    "latitude": 48.105315,
                    "longitude": 7.760001
                },
                "products": {
                    "nationalExpress": false,
                    "national": false,
                    "regionalExp": false,
                    "regional": true,
                    "suburban": true,
                    "bus": true,
                    "ferry": false,
                    "subway": false,
                    "tram": false,
                    "taxi": true
                },
                "station": {
                    "type": "station",
                    "id": "8007294",
                    "name": "Nimburg(Baden)",
                    "location": {
                        "type": "location",
                        "id": "8007294",
                        "latitude": 48.105342,
                        "longitude": 7.760271
                    },
                    "products": {
                        "nationalExpress": false,
                        "national": false,
                        "regionalExp": false,
                        "regional": true,
                        "suburban": true,
                        "bus": true,
                        "ferry": false,
                        "subway": false,
                        "tram": false,
                        "taxi": true
                    }
                }
            },
            "departure": "2020-12-12T23:13:00+01:00",
            "plannedDeparture": "2020-12-12T23:13:00+01:00",
            "departureDelay": null,
            "arrival": "2020-12-12T23:15:00+01:00",
            "plannedArrival": "2020-12-12T23:15:00+01:00",
            "arrivalDelay": null,
            "public": true,
            "walking": true,
            "distance": 51
        },
        {
            "origin": {
                "type": "stop",
                "id": "503550",
                "name": "Nimburg Bahnhof, Teningen",
                "location": {
                    "type": "location",
                    "id": "503550",
                    "latitude": 48.105315,
                    "longitude": 7.760001
                },
                "products": {
                    "nationalExpress": false,
                    "national": false,
                    "regionalExp": false,
                    "regional": true,
                    "suburban": true,
                    "bus": true,
                    "ferry": false,
                    "subway": false,
                    "tram": false,
                    "taxi": true
                },
                "station": {
                    "type": "station",
                    "id": "8007294",
                    "name": "Nimburg(Baden)",
                    "location": {
                        "type": "location",
                        "id": "8007294",
                        "latitude": 48.105342,
                        "longitude": 7.760271
                    },
                    "products": {
                        "nationalExpress": false,
                        "national": false,
                        "regionalExp": false,
                        "regional": true,
                        "suburban": true,
                        "bus": true,
                        "ferry": false,
                        "subway": false,
                        "tram": false,
                        "taxi": true
                    }
                }
            },
            "destination": {
                "type": "stop",
                "id": "420869",
                "name": "Bahnhof/ZOB, Emmendingen",
                "location": {
                    "type": "location",
                    "id": "420869",
                    "latitude": 48.119509,
                    "longitude": 7.848203
                },
                "products": {
                    "nationalExpress": true,
                    "national": false,
                    "regionalExp": false,
                    "regional": true,
                    "suburban": false,
                    "bus": true,
                    "ferry": false,
                    "subway": false,
                    "tram": false,
                    "taxi": true
                },
                "station": {
                    "type": "station",
                    "id": "8001771",
                    "name": "Emmendingen",
                    "location": {
                        "type": "location",
                        "id": "8001771",
                        "latitude": 48.119302,
                        "longitude": 7.847924
                    },
                    "products": {
                        "nationalExpress": true,
                        "national": false,
                        "regionalExp": false,
                        "regional": true,
                        "suburban": false,
                        "bus": true,
                        "ferry": false,
                        "subway": false,
                        "tram": false,
                        "taxi": true
                    }
                }
            },
            "departure": "2020-12-12T23:15:00+01:00",
            "plannedDeparture": "2020-12-12T23:15:00+01:00",
            "departureDelay": null,
            "arrival": "2020-12-12T23:30:00+01:00",
            "plannedArrival": "2020-12-12T23:30:00+01:00",
            "arrivalDelay": null,
            "reachable": true,
            "tripId": "1|590609|0|80|12122020",
            "line": {
                "type": "line",
                "id": "9-rbgast-7204",
                "fahrtNr": "0",
                "name": "AST 7204",
                "public": true,
                "adminCode": "rbgAST",
                "mode": "taxi",
                "product": "taxi",
                "operator": {
                    "type": "operator",
                    "id": "sudbadenbus",
                    "name": "Südbadenbus"
                }
            },
            "direction": "Emmendingen Bf",
            "arrivalPlatform": null,
            "plannedArrivalPlatform": null,
            "departurePlatform": null,
            "plannedDeparturePlatform": null
        },
        {
            "origin": {
                "type": "stop",
                "id": "420869",
                "name": "Bahnhof/ZOB, Emmendingen",
                "location": {
                    "type": "location",
                    "id": "420869",
                    "latitude": 48.119509,
                    "longitude": 7.848203
                },
                "products": {
                    "nationalExpress": true,
                    "national": false,
                    "regionalExp": false,
                    "regional": true,
                    "suburban": false,
                    "bus": true,
                    "ferry": false,
                    "subway": false,
                    "tram": false,
                    "taxi": true
                },
                "station": {
                    "type": "station",
                    "id": "8001771",
                    "name": "Emmendingen",
                    "location": {
                        "type": "location",
                        "id": "8001771",
                        "latitude": 48.119302,
                        "longitude": 7.847924
                    },
                    "products": {
                        "nationalExpress": true,
                        "national": false,
                        "regionalExp": false,
                        "regional": true,
                        "suburban": false,
                        "bus": true,
                        "ferry": false,
                        "subway": false,
                        "tram": false,
                        "taxi": true
                    }
                }
            },
            "destination": {
                "type": "stop",
                "id": "8001771",
                "name": "Emmendingen",
                "location": {
                    "type": "location",
                    "id": "8001771",
                    "latitude": 48.119302,
                    "longitude": 7.847924
                },
                "products": {
                    "nationalExpress": true,
                    "national": false,
                    "regionalExp": false,
                    "regional": true,
                    "suburban": false,
                    "bus": true,
                    "ferry": false,
                    "subway": false,
                    "tram": false,
                    "taxi": true
                }
            },
            "departure": "2020-12-12T23:30:00+01:00",
            "plannedDeparture": "2020-12-12T23:30:00+01:00",
            "departureDelay": null,
            "arrival": "2020-12-12T23:34:00+01:00",
            "plannedArrival": "2020-12-12T23:34:00+01:00",
            "arrivalDelay": null,
            "public": true,
            "walking": true,
            "distance": 52
        },
        {
            "origin": {
                "type": "stop",
                "id": "8001771",
                "name": "Emmendingen",
                "location": {
                    "type": "location",
                    "id": "8001771",
                    "latitude": 48.119302,
                    "longitude": 7.847924
                },
                "products": {
                    "nationalExpress": true,
                    "national": false,
                    "regionalExp": false,
                    "regional": true,
                    "suburban": false,
                    "bus": true,
                    "ferry": false,
                    "subway": false,
                    "tram": false,
                    "taxi": true
                }
            },
            "destination": {
                "type": "stop",
                "id": "8000107",
                "name": "Freiburg(Breisgau) Hbf",
                "location": {
                    "type": "location",
                    "id": "8000107",
                    "latitude": 47.997974,
                    "longitude": 7.841344
                },
                "products": {
                    "nationalExpress": true,
                    "national": true,
                    "regionalExp": true,
                    "regional": true,
                    "suburban": true,
                    "bus": true,
                    "ferry": false,
                    "subway": false,
                    "tram": true,
                    "taxi": false
                }
            },
            "departure": "2020-12-12T23:54:00+01:00",
            "plannedDeparture": "2020-12-12T23:54:00+01:00",
            "departureDelay": null,
            "arrival": "2020-12-13T00:11:00+01:00",
            "plannedArrival": "2020-12-13T00:11:00+01:00",
            "arrivalDelay": null,
            "reachable": true,
            "tripId": "1|283389|0|80|12122020",
            "line": {
                "type": "line",
                "id": "rb-17141",
                "fahrtNr": "17141",
                "name": "RB 17141",
                "public": true,
                "adminCode": "8006C5",
                "mode": "train",
                "product": "regional",
                "operator": {
                    "type": "operator",
                    "id": "db-regio-ag-baden-wurttemberg",
                    "name": "DB Regio AG Baden-Württemberg"
                }
            },
            "direction": "Basel Bad Bf",
            "arrivalPlatform": null,
            "plannedArrivalPlatform": null,
            "departurePlatform": "2",
            "plannedDeparturePlatform": "2"
        }
    ],
    "refreshToken": "¶HKI¶T$A=1@O=Bahlingen Riedlen@L=8007310@a=128@$A=1@O=Nimburg(Baden)@L=8007294@a=128@$202012122311$202012122313$S     12$$1$$$§W$A=1@O=Nimburg(Baden)@L=8007294@a=128@$A=1@O=Nimburg Bahnhof, Teningen@L=503550@a=128@$202012122313$202012122315$$$1$$$§T$A=1@O=Nimburg Bahnhof, Teningen@L=503550@a=128@$A=1@O=Bahnhof/ZOB, Emmendingen@L=420869@a=128@$202012122315$202012122330$AST 7204$$1$$$§W$A=1@O=Bahnhof/ZOB, Emmendingen@L=420869@a=128@$A=1@O=Emmendingen@L=8001771@a=128@$202012122330$202012122334$$$1$$$§T$A=1@O=Emmendingen@L=8001771@a=128@$A=1@O=Freiburg(Breisgau) Hbf@L=8000107@a=128@$202012122354$202012130011$RB 17141$$1$$$",
    "remarks": [],
    "price": null
}
gaudes commented 3 years ago

Endpoint is "journeys". Profile is "db"

Search parameters are:

"station_from":"8007310" "station_to":"8000107" "transfers":"2 "number_of_departures":"5"

derhuerst commented 3 years ago

Looking at the stack trace, the error occurs in format/products-filter.js, which is called when formatting the request, not when parsing the response. Please make sure the iobroker plugin passes the valid options into journeys().

Can you get your iobroker setup to log what is being passed in? You could, for example, add a console.log() call in /opt/iobroker/node_modules/iobroker.fahrplan/lib/route.js line 88, above this line:

aRouteResult = await this.helper.hClient.journeys(this.StationFrom.id.toString(), this.StationTo.id.toString(), RouteOptions.returnRouteOptions());
gaudes commented 3 years ago

Got it, excuse the Issue.

User disabled all products in configuration :-/

One more thing to do when validating the configuration entered by user :-)

derhuerst commented 3 years ago

Glad I could help!