Skip to content

TripRequest not working #29

@iKK001

Description

@iKK001

I tried your ojp-js library. Great work by the way !!

And unfortunately, I am still doing something wrong, possibly, when trying to get a TripRequest.

Maybe you can help me.

Here is my example code :

import * as OJP from "ojp-sdk"

const fromLoc = OJP.Location.initWithStopPlaceRef("8507000", "Bern")
const toLoc = OJP.Location.initWithStopPlaceRef("8503000", "Zurich")
const fromLocation = new OJP.TripLocationPoint(fromLoc)
const toLocation = new OJP.TripLocationPoint(toLoc)

const tripRequestParams = OJP.TripsRequestParams.initWithLocationsAndDate(
    fromLocation,
    toLocation,
    new Date(),
)

if (tripRequestParams) {
    const stage = {
        key: "SBB",
        apiEndpoint: "https://api.opentransportdata.swiss/ojp2020",
        authBearerKey:
            "57c5dbbbf1fe4d0001000018e0f7158cb2b347e3a6745e3ef949e7bf",
    }
    const tripRequest = new OJP.TripRequest(stage, tripRequestParams)
    console.log("hmmmmmmmmm 1")
    tripRequest.fetchResponse((responseText: any, errorData: any) => {
        console.log("hmmmmmmmmm 2")
        if (errorData) {
            console.error(errorData)
        }
        console.log(responseText)
    })
}

And here is the error log:

[BUILD] hmmmmmmmmm 1
[BUILD] <userDir>/test/node_modules/ojp-sdk/lib/trips/trips-response.js:12
[BUILD]         const responseXML = new DOMParser().parseFromString(responseXMLText, 'application/xml');
[BUILD]                             ^
[BUILD] 
[BUILD] ReferenceError: DOMParser is not defined
[BUILD]     at Function.initWithXML (<userDir>/test/node_modules/ojp-sdk/lib/trips/trips-response.js:12:29)
[BUILD]     at <anonymous> (<userDir>/test/node_modules/ojp-sdk/lib/request/trips-request/trips-request.js:14:49)
[BUILD]     at <anonymous> (<userDir>/test/node_modules/ojp-sdk/lib/request/base-request.js:61:17)
[BUILD]     at processTicksAndRejections (node:internal/process/task_queues:96:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[BUILD] yarn tsx src/index.ts exited with code 1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

As you can see, it never reaches the hmmmmmmmmm 2 callback.

It obviously asks for a DOMParser() - but what does that mean ?

I do not want to make a frontend-App. But rather use it inside a Raspberry Pi or similar simply to get trips from A to B.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions