3

hi I have a really complicated problem. So I created a new repo for this problem at github. So you can clone it and see what the problem is.

https://github.com/guitar9/hafas-client-example

I am using https://github.com/public-transport/hafas-client in this project to get train and railway station informations.

client.journeys(münchenHbf, münchenPassing)
.then((response)=>{
  console.log('===============response=====================');
  console.log(response);
  console.log('====================================');
})
.catch(console.error)

the request is in

node_modules/hafas-client/lib/request

Problem is in debug mode everything works fine (shake phone and start remote JS Debugging), but when i stop JS Debugging i get Error 'PARSE'.

So i looked up in request.js and logged out request and response in debug mode and not in debug mode.

Request Debug Mode

{
    "method": "post",
    "body": "{\"lang\":\"en\",\"svcReqL\":[{\"cfg\":{\"polyEnc\":\"GPA\"},\"meth\":\"TripSearch\",\"req\":{\"outDate\":\"20180614\",\"outTime\":\"174837\",\"ctxScr\":null,\"getPasslist\":false,\"maxChg\":5,\"minChgTime\":0,\"depLocL\":[{\"lid\":\"A=1@L=008000261@\"}],\"viaLocL\":null,\"arrLocL\":[{\"lid\":\"A=1@L=008004158@\"}],\"jnyFltrL\":[{\"type\":\"PROD\",\"mode\":\"INC\",\"value\":\"1023\"},{\"type\":\"META\",\"mode\":\"INC\",\"meta\":\"notBarrierfree\"}],\"getTariff\":false,\"outFrwd\":true,\"getPT\":true,\"getIV\":false,\"getPolyline\":false,\"numF\":5,\"trfReq\":{\"jnyCl\":2,\"tvlrProf\":[{\"type\":\"E\",\"redtnCard\":null}],\"cType\":\"PK\"}}}],\"client\":{\"id\":\"DB\",\"v\":\"16040000\",\"type\":\"IPH\",\"name\":\"DB Navigator\"},\"ext\":\"DB.R15.12.a\",\"ver\":\"1.16\",\"auth\":{\"type\":\"AID\",\"aid\":\"n91dB8Z77MLdoR0K\"}}",
    "headers": {
        "Content-Type": "application/json",
        "Accept": "application/json",
        "user-agent": "https://github.com/public-transport/hafas-client"
    },
    "query": {
        "checksum": "6af3b74db20e14c7f94012e3de55dce6"
    }
}

Response Debug Mode

all informations. everything okay.

Request not in debug mode

{
    "method": "post",
    "body": "{\"lang\":\"en\",\"svcReqL\":[{\"cfg\":{\"polyEnc\":\"GPA\"},\"meth\":\"TripSearch\",\"req\":{\"outDate\":\"Invalid DateTime\",\"outTime\":\"Invalid DateTime\",\"ctxScr\":null,\"getPasslist\":false,\"maxChg\":5,\"minChgTime\":0,\"depLocL\":[{\"lid\":\"A=1@L=008000261@\"}],\"viaLocL\":null,\"arrLocL\":[{\"lid\":\"A=1@L=008004158@\"}],\"jnyFltrL\":[{\"type\":\"PROD\",\"mode\":\"INC\",\"value\":\"1023\"},{\"type\":\"META\",\"mode\":\"INC\",\"meta\":\"notBarrierfree\"}],\"getTariff\":false,\"outFrwd\":true,\"getPT\":true,\"getIV\":false,\"getPolyline\":false,\"numF\":5,\"trfReq\":{\"jnyCl\":2,\"tvlrProf\":[{\"type\":\"E\",\"redtnCard\":null}],\"cType\":\"PK\"}}}],\"client\":{\"id\":\"DB\",\"v\":\"16040000\",\"type\":\"IPH\",\"name\":\"DB Navigator\"},\"ext\":\"DB.R15.12.a\",\"ver\":\"1.16\",\"auth\":{\"type\":\"AID\",\"aid\":\"n91dB8Z77MLdoR0K\"}}",
    "headers": {
        "Content-Type": "application/json",
        "Accept": "application/json",
        "user-agent": "https://github.com/public-transport/hafas-client"
    },
    "query": {
        "checksum": "0d8186da7b06f9cc094075a2a6e21b00"
    }
}

Response not in debug mode

{
    "ver": "1.16",
    "ext": "DB.R15.12.a",
    "lang": "eng",
    "id": "",
    "err": "PARSE",
    "svcResL": []
}

I have compared the requests. Here you can see the difference between the two request. https://www.diffnow.com/?report=pvuq7 The problem is outDate, outTime and checksum. Somebody can help me?

5
  • All your code might not be executing. Android uses Proguard to remove unused resources, but Proguard doesn't always know what is unused, so you'd need to configure that in the proguard-rules.pro file. The reason it works in debug mode (IF Proguard is the one causing the problem), is that Android skips the Proguard optimisation so as to quicken build times. Commented Jun 14, 2018 at 16:07
  • i commented out minifyEnabled and enableProguardInReleaseBuilds in build.gradle. But same problem... Commented Jun 14, 2018 at 16:22
  • I tried that too (in my native Android application), it didn't seem to make a difference; so it seemed there was no easy way to disable Proguard. I suggest you use it regardless to prevent reverse-engineering. Try logging in each relevant method and compare the logs with the regular and debug APKs to see what's missing. Commented Jun 14, 2018 at 16:25
  • i found this in build.gradle def enableProguardInReleaseBuilds = false. So Proguard is disabled per default Commented Jun 14, 2018 at 17:13
  • Your console.log's will break your app if you are not running external js debugger. Since your native app environment will not have console -global variable and JavaScript throws error. Commented Jun 25, 2018 at 7:38

2 Answers 2

6
+100

The problem is the usage of the Luxon library within hafas-client library. You will see that your code provided in the repo runs fine on iOS and on android only with remote debugging enabled. Why?

When remote debugging is enabled the code does not run in your phone but in the V8 engine of your chrome browser. When the remote debugging is disabled, code runs on your phone, where in case of android, it runs on a JavaScriptCore (JSC) engine from late 2014 that was compiled with custom setup for react native - that can, potentially, deliver different results.

As the luxon docs point out, support for react native on android is limited.

On iOS, react native uses the JSC available from the OS, which also includes intl features. The reason JSC on android does not have int support is that JSC is bundled together with the apk, and compiling it with intl support would increase the apk size by several MB.

With a bit of cutomizations (forking the hafas client) and working around the date problems, I believe you should be able to fix this. You may also use this but beware that you may run into other sorts of issues that may be hard to get help with (for a while, the Expo client used to use the JSC compiled from this repo but they had to stop using the custom build because of some problems).

Alternatively, you may try using intl polyfill

How did I find out? here you'll see that the error object contains a bunch of extra information. When you were logging the error, you were just getting the description field, but if you log the request field, you'll see that it contains "outDate": "Invalid DateTime". There it is!

Sign up to request clarification or add additional context in comments.

4 Comments

and whats about the checksum? The checksum is also different
added jsc in example repo: github.com/guitar9/hafas-client-example.git bu still not works
@KTWorks the request also contains invalid dateTime, so the checksum is different. As for the custom JSC, you will need to specify correct build flags so that it is compiled with intl support.
I got a different issue, api response is correct while in debugging mode, but when i stop debugging, the api responded 200 but not the updated response, but in postman the same api works perfectly.. i did'nt know what to do now...
2

Author of hafas-client here. Posting as an answer for visibility and because I don't have the reputation to comment.

As I have documented in https://github.com/public-transport/hafas-client/issues/56#issuecomment-399915315, I managed to use [email protected] out-of-the-box in react-native, after I had added the node-libs-react-native shims. Please try this.

There might of course be another issue related to luxon (as discussed in https://stackoverflow.com/a/51005700), but at least querying data without EPARSE errors or undecoded response payloads are not related to luxon and apparently solved.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.