Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"PARSE" Error when using with react-native #56

Closed
guitar9 opened this issue May 28, 2018 · 36 comments
Closed

"PARSE" Error when using with react-native #56

guitar9 opened this issue May 28, 2018 · 36 comments
Labels

Comments

@guitar9
Copy link

guitar9 commented May 28, 2018

Hi i get following error when i use it with react native. This is only with client.journys(..). client.locations(..) works fine.

This error is only when i am not in dubugging mode. When i am in debugging mode it works.
This is my code:

const createClient = require('hafas-client')
const dbProfile = require('hafas-client/p/db')
const client = createClient(dbProfile)
const münchenHbf = {
  type: 'station',
  id: '008000261',
  name: 'München Hbf',
  locations: {
    type: 'location',
    latitude:48.140364,
    longitude:11.558735
  }
}

const münchenPassing = {
  type: 'station',
  id: '008004158',
  name: 'München-Pasing',
  locations: {
    type: 'location',
    latitude:48.150036,
    longitude:11.461624
  }
}
const opt = {
  //var date2 = new Date('2018-12-17T03:24:00');
	when: new Date('2018-05-29T06:40:00'),
	whenRepresents: 'departure', // use 'arrival' for journeys arriving before `when`
	//earlierThan: null, // ref to get journeys earlier than the last query
	//laterThan: null, // ref to get journeys later than the last query
	results: 5, // how many journeys?
	via: null, // let journeys pass this station
	passedStations: false, // return stations on the way?
	transfers: 5, // maximum of 5 transfers
	transferTime: 0, // minimum time for a single transfer in minutes
	accessibility: 'none', // 'none', 'partial' or 'complete'
	bike: false, // only bike-friendly journeys
	products: {
		// these entries may vary from profile to profile
		suburban: true,
		subway: true,
		tram: true,
		bus: true,
		ferry: true,
		//express: true,
		regional: true
	},
	tickets: false, // return tickets? only available with some profiles
	polylines: false // return a shape for each leg?
}
    client.journeys(münchenPassing, münchenHbf, opt)
    .then((arr)=>{
      console.log('===============arr=====================');
      console.log(arr);
      console.log('====================================');

    })
    .catch(console.error)


  }
PARSE
request
    request.js:54:13
more
    index.js:134:18
journeys
    index.js:168:14
componentDidMount
    App.js:130:20
proxiedComponentDidMount
    createPrototypeProxy.js:61:45
commitLifeCycles
    ReactNativeRenderer-dev.js:10627:12
commitAllLifeCycles
    ReactNativeRenderer-dev.js:12512:10
invokeGuardedCallback
    ReactNativeRenderer-dev.js:39:15
invokeGuardedCallback
    ReactNativeRenderer-dev.js:221:34
commitRoot
    ReactNativeRenderer-dev.js:12677:10
completeRoot
    ReactNativeRenderer-dev.js:13685:46
performWorkOnRoot
    ReactNativeRenderer-dev.js:13635:23
performWork
    ReactNativeRenderer-dev.js:13545:26
performSyncWork
    ReactNativeRenderer-dev.js:13506:16
requestWork
    ReactNativeRenderer-dev.js:13392:6
scheduleWorkImpl
    ReactNativeRenderer-dev.js:13259:24
scheduleWork
    ReactNativeRenderer-dev.js:13207:28
scheduleRootUpdate
    ReactNativeRenderer-dev.js:13930:17
_updateContainerAtExpirationTime
    ReactNativeRenderer-dev.js:13966:6
updateContainer
    ReactNativeRenderer-dev.js:13991:8
render
    ReactNativeRenderer-dev.js:14726:35
renderApplication
    renderApplication.js:49:21
run
    AppRegistry.js:102:10
runApplication
    AppRegistry.js:194:26
__callFunction
    MessageQueue.js:351:47
<unknown>
    MessageQueue.js:116:26
__guardSafe
    MessageQueue.js:314:6
callFunctionReturnFlushedQueue
    MessageQueue.js:115:17

@derhuerst
Copy link
Member

Which version of hafas-client do you use?

@derhuerst derhuerst added the bug label May 29, 2018
@derhuerst
Copy link
Member

cannot reproduce.

@guitar9
Copy link
Author

guitar9 commented May 31, 2018

i am using react native and the version is 2.8.0 but i made some changes. import buffer, import random-bytes, ...

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

Now i get the Error JSON Parse error: Unrecongnized token '?'

if I change

'Accept-Encoding': 'gzip, deflate',

to

'Accept': 'application/json',

i get the error PARSE

@guitar9
Copy link
Author

guitar9 commented May 31, 2018

This is the header which is send from a phone with the Deutsche Bahn App. With this header i get the same error.

image

@guitar9
Copy link
Author

guitar9 commented May 31, 2018

in request .js
image

image

@guitar9
Copy link
Author

guitar9 commented May 31, 2018

the weird thing is when i change
'Accept-Encoding': 'gzip, deflate'
to
'Accept-Encoding': 'application/json'
it goes, But only in debug Mode. In normal mode i get error "PARSE"

@guitar9
Copy link
Author

guitar9 commented May 31, 2018

if I commend out the error part i get error "undefined is not a object (evaluating 'b.svcResL[0].res)"

		.then((b) => {
			console.log('=============here is error=======================');
			console.log(b);
			console.log('====================================');
			// if (b.err) {
			// 	err.message = b.err
			// 	throw err
			// }
			// if (!b.svcResL || !b.svcResL[0]) {
			// 	err.message = 'invalid response'
			// 	throw err
			// }
			// if (b.svcResL[0].err !== 'OK') {
			// 	err.message = b.svcResL[0].errTxt || b.svcResL[0].err
			// 	throw err
			// }
			const d = b.svcResL[0].res
			const c = d.common || {}

			if (Array.isArray(c.remL)) {
				d.remarks = c.remL.map(rem => profile.parseRemark(profile, rem))
			}
			if (Array.isArray(c.opL)) {
				d.operators = c.opL.map(op => profile.parseOperator(profile, op))
			}
			if (Array.isArray(c.prodL)) {
				const parse = profile.parseLine(profile, d.operators)
				d.lines = c.prodL.map(parse)
			}
			if (Array.isArray(c.locL)) {
				const parse = loc => profile.parseLocation(profile, loc, d.lines)
				d.locations = c.locL.map(parse)
			}
			return d
		})

@derhuerst
Copy link
Member

i am using react native and the version is 2.8.0 but i made some changes. import buffer, import random-bytes, ...

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

I am willing to make hafas-client work in react-native without any modifications. I will create a branch for you to try.

@guitar9
Copy link
Author

guitar9 commented Jun 1, 2018 via email

@derhuerst
Copy link
Member

derhuerst commented Jun 1, 2018

In the react-native-browser branch, I've included ponyfills for Buffer and Symbol. Keep in mind that it branches off next, so it will have minor incompatibilities with [email protected].

Will look into the HTTP headers thing.

@guitar9
Copy link
Author

guitar9 commented Jun 1, 2018

get now error:
Project :app declares a dependency from configuration 'compile' to configuration 'default' which is not declared in the descriptor for project :react-native-randombytes
Maybe this problem is only for me because already linked react-native randombytes...

But after installing react-native-randombytes i get error undefined is not a object ( evaluating b.svcResL[0].res)

@derhuerst
Copy link
Member

What about now? I pushed c78f64d.

@guitar9
Copy link
Author

guitar9 commented Jun 1, 2018

I deleted the folder hafas-client and installed it again with

npm install git://github.com:public-transport/hafas-client.git#react-native-browser --save

how ever now i get error cant find variable Buffer.

Can't find variable: Buffer
<unknown>
    util.js:103:26
loadModuleImplementation
    require.js:214:12
guardedLoadModule
    require.js:148:36
_require
    require.js:132:20
<unknown>
    _stream_readable.js:46:11
loadModuleImplementation
    require.js:214:12
guardedLoadModule
    require.js:148:36
_require
    require.js:132:20
<unknown>
    readable.js:2:27
loadModuleImplementation
    require.js:214:12
guardedLoadModule
    require.js:148:36
_require
    require.js:132:20
<unknown>
    index.js:28:18
loadModuleImplementation
    require.js:214:12
guardedLoadModule
    require.js:148:36
_require
    require.js:132:20
<unknown>
    index.js:3:16
loadModuleImplementation
    require.js:214:12
guardedLoadModule
    require.js:148:36
_require
    require.js:132:20
<unknown>
    index.js:3:15
loadModuleImplementation
    require.js:214:12
guardedLoadModule
    require.js:148:36
_require
    require.js:132:20
<unknown>
    browser.js:3:10
loadModuleImplementation
    require.js:214:12
guardedLoadModule
    require.js:148:36
_require
    require.js:132:20
<unknown>
    request.js:3:19
loadModuleImplementation
    require.js:214:12
guardedLoadModule
    require.js:148:36
_require
    require.js:132:20
<unknown>
    index.js:11:17
loadModuleImplementation
    require.js:214:12
guardedLoadModule
    require.js:148:36
_require
    require.js:132:20
<unknown>
    App.js:99:21
loadModuleImplementation
    require.js:214:12
guardedLoadModule
    require.js:148:36
_require
    require.js:132:20
<unknown>
    index.js:2
loadModuleImplementation
    require.js:214:12
guardedLoadModule
    require.js:141:45
_require
    require.js:132:20
global code
    

@guitar9
Copy link
Author

guitar9 commented Jun 3, 2018

tried to change .json() to .text() and comment out
//'Accept-Encoding': 'gzip, deflate',

But only in debugging mode. In production mode i get same error "PARSE". This is really weird.

this is my response:
request.js 71

{"ver":"1.16","ext":"DB.R15.12.a","lang":"eng","id":"cam8xxyk6uipy4w8","cInfo":{"code":"OK","url":"","msg":""},"svcResL":[{"meth":"TripSearch","err":"OK","res":{"common":{"locL":[{"lid":"A=1@O=Hünfeld@X=9762456@Y=50673272@U=80@L=8003016@","type":"S","name":"Hünfeld","icoX":0,"extId":"8003016","crd":{"x":9762915,"y":50673218,"z":0,"type":"WGS84","layerX":0,"crdSysX":0},"pCls":554},{"lid":"A=1@O=Fulda@X=9683980@Y=50554722@U=80@L=8000115@","type":"S","name":"Fulda","icoX":0,"extId":"8000115","crd":{"x":9684169,"y":50554794,"z":0,"type":"WGS84","layerX":0,"crdSysX":0},"pCls":559},{"lid":"A=1@O=Ludwigsau-Friedlos@X=9743327@Y=50896879@U=80@L=8002103@","type":"S","name":"Ludwigsau-Friedlos","icoX":0,"extId":"8002103","crd":{"x":9743282,"y":50896978,"z":0,"type":"WGS84","layerX":0,"crdSysX":0},"pCls":552}],"prodL":[{"name":"RB 24193","number":"24193","icoX":2,"cls":8,"oprX":0,"prodCtx":{"name":"RB 24193","num":"24193","matchId":"7","catOut":"RB","catOutS":"DPN","catOutL":"cantus Verkehrsgesellschaft","catIn":"DPN","catCode":"3","admin":"N4____"}},{"name":"RB 24197","number":"24197","icoX":2,"cls":8,"oprX":0,"prodCtx":{"name":"RB 24197","num":"24197","matchId":"5","catOut":"RB","catOutS":"DPN","catOutL":"cantus Verkehrsgesellschaft","catIn":"DPN","catCode":"3","admin":"N4____"}},{"name":"RB 24067","number":"24067","icoX":2,"cls":8,"oprX":0,"prodCtx":{"name":"RB 24067","num":"24067","matchId":"7","catOut":"RB","catOutS":"DPN","catOutL":"cantus Verkehrsgesellschaft","catIn":"DPN","catCode":"3","admin":"N4____"}},{"name":"RB 24203","number":"24203","icoX":2,"cls":8,"oprX":0,"prodCtx":{"name":"RB 24203","num":"24203","matchId":"5","catOut":"RB","catOutS":"DPN","catOutL":"cantus Verkehrsgesellschaft","catIn":"DPN","catCode":"3","admin":"N4____"}},{"name":"RB 24205","number":"24205","icoX":2,"cls":8,"oprX":0,"prodCtx":{"name":"RB 24205","num":"24205","matchId":"5","catOut":"RB","catOutS":"DPN","catOutL":"cantus Verkehrsgesellschaft","catIn":"DPN","catCode":"3","admin":"N4____"}}],"polyL":[],"layerL":[{"id":"standard","name":"standard","index":0,"annoCnt":0}],"crdSysL":[{"id":"standard","index":0,"type":"WGS84","dim":3}],"opL":[{"name":"cantus Verkehrsgesellschaft","icoX":1}],"remL":[{"type":"A","code":"FB","prio":260,"icoX":3,"txtN":"Number of bicycles conveyed limited"}],"icoL":[{"res":"STA"},{"res":"DPN","txt":"cantus Verkehrsgesellschaft"},{"res":"RB"},{"res":"attr_bike"}]},"outConL":[{"cid":"C-0","date":"20180529","dur":"003500","chg":0,"sDays":{"sDaysR":"Mo - Fr","sDaysI":"not 31. May, 3. Oct","sDaysB":"7CF871E7CF9F3E7CF9F3E7CF9F3C3CF9F3E5CE9F1E74F9F3E7CF9F3E7CF9F3E7CF9F3E7CF9B3E7CF9F3E7CF9F3E0"},"dep":{"locX":2,"dPlatfS":"1","dInR":true,"dTimeS":"065200","dTZOffset":120,"type":"N"},"arr":{"locX":1,"aPlatfS":"4","aOutR":true,"aTimeS":"072700","aProgType":"PROGNOSED","aTZOffset":120,"type":"N"},"secL":[{"type":"JNY","icoX":2,"dep":{"locX":2,"dPlatfS":"1","dInR":true,"dTimeS":"065200","dTZOffset":120,"type":"N"},"arr":{"locX":1,"aPlatfS":"4","aOutR":true,"aTimeS":"072700","aProgType":"PROGNOSED","aTZOffset":120,"type":"N"},"jny":{"jid":"1|263984|0|80|29052018","prodX":0,"dirTxt":"Fulda","status":"P","isRchbl":true,"ctxRecon":"T$A=1@O=Ludwigsau-Friedlos@L=8002103@a=128@$A=1@O=Fulda@L=8000115@a=128@$201805290652$201805290727$RB 24193$$1$","msgL":[{"type":"REM","remX":0,"fLocX":2,"tLocX":1,"tagL":["RES_JNY_DTL_L"]}],"subscr":"F"}}],"ctxRecon":"T$A=1@O=Ludwigsau-Friedlos@L=8002103@a=128@$A=1@O=Fulda@L=8000115@a=128@$201805290652$201805290727$RB 24193$$1$","trfRes":{"statusCode":"NA","fareSetL":[{"fareL":[{"desc":"Fares not available","prc":-1,"isFromPrice":false,"isBookable":false,"isUpsell":false}]}]},"conSubscr":"F","sotRating":3,"isSotCon":false,"showARSLink":false,"sotCtxt":{"cnLocX":1,"calcDate":"20180603","jid":"1|263984|0|80|-1","locMode":"AT_DESTINATION","pLocX":0,"reqMode":"UNKNOWN","sectX":0,"calcTime":"223450"},"useableTime":25,"cksum":"61fea22e_2"},{"cid":"C-1","date":"20180529","dur":"003100","chg":0,"sDays":{"sDaysR":"Mo - Fr","sDaysI":"not 31. May, 3. Oct","sDaysB":"7CF871E7CF9F3E7CF9F3E7CF9F3C3CF9F3E5CE9F1E74F9F3E7CF9F3E7CF9F3E7CF9F3E7CF9B3E7CF9F3E7CF9F3E0"},"dep":{"locX":2,"dPlatfS":"1","dInR":true,"dTimeS":"072200","dTZOffset":120,"type":"N"},"arr":{"locX":1,"aPlatfS":"3","aOutR":true,"aTimeS":"075300","aProgType":"PROGNOSED","aTZOffset":120,"type":"N"},"secL":[{"type":"JNY","icoX":2,"dep":{"locX":2,"dPlatfS":"1","dInR":true,"dTimeS":"072200","dTZOffset":120,"type":"N"},"arr":{"locX":1,"aPlatfS":"3","aOutR":true,"aTimeS":"075300","aProgType":"PROGNOSED","aTZOffset":120,"type":"N"},"jny":{"jid":"1|263993|0|80|29052018","prodX":1,"dirTxt":"Fulda","status":"P","isRchbl":true,"ctxRecon":"T$A=1@O=Ludwigsau-Friedlos@L=8002103@a=128@$A=1@O=Fulda@L=8000115@a=128@$201805290722$201805290753$RB 24197$$1$","msgL":[{"type":"REM","remX":0,"fLocX":2,"tLocX":1,"tagL":["RES_JNY_DTL_L"]}],"subscr":"F"}}],"ctxRecon":"T$A=1@O=Ludwigsau-Friedlos@L=8002103@a=128@$A=1@O=Fulda@L=8000115@a=128@$201805290722$201805290753$RB 24197$$1$","trfRes":{"statusCode":"NA","fareSetL":[{"fareL":[{"desc":"Fares not available","prc":-1,"isFromPrice":false,"isBookable":false,"isUpsell":false}]}]},"conSubscr":"F","sotRating":3,"isSotCon":false,"showARSLink":false,"sotCtxt":{"cnLocX":1,"calcDate":"20180603","jid":"1|263993|0|80|-1","locMode":"AT_DESTINATION","pLocX":0,"reqMode":"UNKNOWN","sectX":0,"calcTime":"223450"},"useableTime":21,"cksum":"ab4cb433_2"},{"cid":"C-2","date":"20180529","dur":"003100","chg":0,"sDays":{"sDaysR":"Mo - Fr","sDaysI":"not 3. Oct","sDaysB":"7CF871E7CF9F3E7CF9F3E7CF9F3C3CF9F3E5CE9F1E7CF9F3E7CF9F3E7CF9F3E7CF9F3E7CF9B3E7CF9F3E7CF9F3E0"},"dep":{"locX":2,"dPlatfS":"1","dInR":true,"dTimeS":"082600","dTZOffset":120,"type":"N"},"arr":{"locX":1,"aPlatfS":"8","aOutR":true,"aTimeS":"085700","aProgType":"PROGNOSED","aTZOffset":120,"type":"N"},"secL":[{"type":"JNY","icoX":2,"dep":{"locX":2,"dPlatfS":"1","dInR":true,"dTimeS":"082600","dTZOffset":120,"type":"N"},"arr":{"locX":1,"aPlatfS":"8","aOutR":true,"aTimeS":"085700","aProgType":"PROGNOSED","aTZOffset":120,"type":"N"},"jny":{"jid":"1|263899|0|80|29052018","prodX":2,"dirTxt":"Fulda","status":"P","isRchbl":true,"ctxRecon":"T$A=1@O=Ludwigsau-Friedlos@L=8002103@a=128@$A=1@O=Fulda@L=8000115@a=128@$201805290826$201805290857$RB 24067$$1$","msgL":[{"type":"REM","remX":0,"fLocX":2,"tLocX":1,"tagL":["RES_JNY_DTL_L"]}],"subscr":"F"}}],"ctxRecon":"T$A=1@O=Ludwigsau-Friedlos@L=8002103@a=128@$A=1@O=Fulda@L=8000115@a=128@$201805290826$201805290857$RB 24067$$1$","trfRes":{"statusCode":"NA","fareSetL":[{"fareL":[{"desc":"Fares not available","prc":-1,"isFromPrice":false,"isBookable":false,"isUpsell":false}]}]},"conSubscr":"F","sotRating":3,"isSotCon":false,"showARSLink":false,"sotCtxt":{"cnLocX":1,"calcDate":"20180603","jid":"1|263899|0|80|-1","locMode":"AT_DESTINATION","pLocX":0,"reqMode":"UNKNOWN","sectX":0,"calcTime":"223450"},"useableTime":21,"cksum":"226fc082_2"},{"cid":"C-3","date":"20180529","dur":"003200","chg":0,"sDays":{"sDaysR":"Mo - Sa","sDaysI":"not 31. May, 3. Oct","sDaysB":"7EFC79F7EFDFBF7EFDFBF7EFDFBD3EFDFBF5EEDF9F76FDFBF7EFDFBF7EFDFBF7EFDFBF7EFDBBF7EFDFBF7EFDFBF0"},"dep":{"locX":2,"dPlatfS":"1","dInR":true,"dTimeS":"090500","dTZOffset":120,"type":"N"},"arr":{"locX":1,"aPlatfS":"4","aOutR":true,"aTimeS":"093700","aProgType":"PROGNOSED","aTZOffset":120,"type":"N"},"secL":[{"type":"JNY","icoX":2,"dep":{"locX":2,"dPlatfS":"1","dInR":true,"dTimeS":"090500","dTZOffset":120,"type":"N"},"arr":{"locX":1,"aPlatfS":"4","aOutR":true,"aTimeS":"093700","aProgType":"PROGNOSED","aTZOffset":120,"type":"N"},"jny":{"jid":"1|264012|0|80|29052018","prodX":3,"dirTxt":"Fulda","status":"P","isRchbl":true,"ctxRecon":"T$A=1@O=Ludwigsau-Friedlos@L=8002103@a=128@$A=1@O=Fulda@L=8000115@a=128@$201805290905$201805290937$RB 24203$$1$","msgL":[{"type":"REM","remX":0,"fLocX":2,"tLocX":1,"tagL":["RES_JNY_DTL_L"]}],"subscr":"F"}}],"ctxRecon":"T$A=1@O=Ludwigsau-Friedlos@L=8002103@a=128@$A=1@O=Fulda@L=8000115@a=128@$201805290905$201805290937$RB 24203$$1$","trfRes":{"statusCode":"NA","fareSetL":[{"fareL":[{"desc":"Fares not available","prc":-1,"isFromPrice":false,"isBookable":false,"isUpsell":false}]}]},"conSubscr":"F","sotRating":3,"isSotCon":false,"showARSLink":false,"sotCtxt":{"cnLocX":1,"calcDate":"20180603","jid":"1|264012|0|80|-1","locMode":"AT_DESTINATION","pLocX":0,"reqMode":"UNKNOWN","sectX":0,"calcTime":"223450"},"useableTime":22,"cksum":"3e9238df_2"},{"cid":"C-4","date":"20180529","dur":"003200","chg":0,"sDays":{"sDaysR":"daily","sDaysB":"FFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0"},"dep":{"locX":2,"dPlatfS":"1","dInR":true,"dTimeS":"100500","dTZOffset":120,"type":"N"},"arr":{"locX":1,"aPlatfS":"4","aOutR":true,"aTimeS":"103700","aProgType":"PROGNOSED","aTZOffset":120,"type":"N"},"secL":[{"type":"JNY","icoX":2,"dep":{"locX":2,"dPlatfS":"1","dInR":true,"dTimeS":"100500","dTZOffset":120,"type":"N"},"arr":{"locX":1,"aPlatfS":"4","aOutR":true,"aTimeS":"103700","aProgType":"PROGNOSED","aTZOffset":120,"type":"N"},"jny":{"jid":"1|264016|0|80|29052018","prodX":4,"dirTxt":"Fulda","status":"P","isRchbl":true,"ctxRecon":"T$A=1@O=Ludwigsau-Friedlos@L=8002103@a=128@$A=1@O=Fulda@L=8000115@a=128@$201805291005$201805291037$RB 24205$$1$","msgL":[{"type":"REM","remX":0,"fLocX":2,"tLocX":1,"tagL":["RES_JNY_DTL_L"]}],"subscr":"F"}}],"ctxRecon":"T$A=1@O=Ludwigsau-Friedlos@L=8002103@a=128@$A=1@O=Fulda@L=8000115@a=128@$201805291005$201805291037$RB 24205$$1$","trfRes":{"statusCode":"NA","fareSetL":[{"fareL":[{"desc":"Fares not available","prc":-1,"isFromPrice":false,"isBookable":false,"isUpsell":false}]}]},"conSubscr":"F","sotRating":3,"isSotCon":false,"showARSLink":false,"sotCtxt":{"cnLocX":1,"calcDate":"20180603","jid":"1|264016|0|80|-1","locMode":"AT_DESTINATION","pLocX":0,"reqMode":"UNKNOWN","sectX":0,"calcTime":"223450"},"useableTime":22,"cksum":"9be73e94_2"}],"outCtxScrB":"1|OB|MT#11#248092#248092#248127#248127#0#0#165#248076#1#-2147482610#0#1#2|PDH#2e78d4fc5b28d6ad2b8ed96ebb9670ff","outCtxScrF":"1|OF|MT#11#248285#248285#248317#248317#0#0#5#248226#5#-2147482610#0#1#2|PDH#2e78d4fc5b28d6ad2b8ed96ebb9670ff","fpB":"20171210","fpE":"20181208","bfATS":-1,"bfIOSTS":-1,"planrtTS":"1528058057"}}]}

@guitar9
Copy link
Author

guitar9 commented Jun 3, 2018

this what i getting as response when i am not in debug mode:
{"ver":"1.16","ext":"DB.R15.12.a","lang":"eng","id":"","err":"PARSE","svcResL":[]}

@guitar9
Copy link
Author

guitar9 commented Jun 3, 2018

I have different bodys in debug mode and in production mode.
Out date and Out Time is: Invalid Date in production mode and the checksum is in production mode and debug mode not the same.

I have uploaded a comparssion between the two bodys.

DiffNow Comparison Report (1).htm.zip

@derhuerst
Copy link
Member

I have different bodys in debug mode and in production mode.

Which debug and production mode are you referring to?

Out date and Out Time is: Invalid Date in production mode [...].

This is very weird. Will try to figure out why.

In the meanwhile, can you try to, instead of the react-native-browser branch, just use hafas-client@next and node-libs-react-native?

@guitar9
Copy link
Author

guitar9 commented Jun 4, 2018

Which debug and production mode are you referring to?

If I run my app on a device I can open dev menu and start debugger mode on device.
At http://localhost:8081/debugger-ui/ I see then what i have logged out.

@guitar9
Copy link
Author

guitar9 commented Jun 7, 2018

tried to install hafas-client@next and node-libs-react-native.
I had to install es6-symbol and require it in loyalty-cards and comment out
"//'Accept-Encoding': 'gzip, deflate'" in request.js

Than i have the same problem like before. In debug mode everything is fine but in normal mode the checksum and the Out date and Out time are not correct

@guitar9
Copy link
Author

guitar9 commented Jun 7, 2018

Here is my Example Project

DOWNLOAD

@guitar9
Copy link
Author

guitar9 commented Jun 7, 2018

or at github
React Native Hafas Client example Repo

@derhuerst
Copy link
Member

tried to install hafas-client@next and node-libs-react-native.
I had to install es6-symbol and require it in loyalty-cards [...].

I forgot that node-libs-react-native only fixes Node-builtin modules for react-native, but not Node-builtin globals. So my hafas-client@next + node-libs-react-native proposal did't make sense.

Please continue debugging with npm i public-transport/hafas-client#react-native-browser.

I had to [...] and comment out 'Accept-Encoding': 'gzip, deflate' in request.js.

Please keep it. Why would you want to remove it?

Here is my Example Project [...] or at github: React Native Hafas Client example Repo

In your example project, use public-transport/hafas-client#react-native-browser directly.

@derhuerst derhuerst changed the title PARSE Error "PARSE" Error when using with react-native Jun 11, 2018
@guitar9
Copy link
Author

guitar9 commented Jun 11, 2018

have updated it.

now get error from create hash:

The development server returned response error code: 500

URL: http://localhost:8081/index.delta?platform=android&dev=true&minify=false&deltaBundleId=af226ea22bdc3186

Body:
{"originModulePath":"/home/t/ws/react/hafas-client-example/example/node_modules/cipher-base/index.js","targetModuleName":"stream","message":"Unable to resolve module `stream` from `/home/t/ws/react/hafas-client-example/example/node_modules/cipher-base/index.js`: Module `stream` does not exist in the Haste module map\n\nThis might be related to https://github.com/facebook/react-native/issues/4968\nTo resolve try the following:\n  1. Clear watchman watches: `watchman watch-del-all`.\n  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.\n  3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.  4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.","errors":[{"description":"Unable to resolve module `stream` from `/home/t/ws/react/hafas-client-example/example/node_modules/cipher-base/index.js`: Module `stream` does not exist in the Haste module map\n\nThis might be related to https://github.com/facebook/react-native/issues/4968\nTo resolve try the following:\n  1. Clear watchman watches: `watchman watch-del-all`.\n  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.\n  3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.  4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`."}],"name":"Error","stack":"Error: Unable to resolve module `stream` from `/home/t/ws/react/hafas-client-example/example/node_modules/cipher-base/index.js`: Module `stream` does not exist in the Haste module map\n\nThis might be related to https://github.com/facebook/react-native/issues/4968\nTo resolve try the following:\n  1. Clear watchman watches: `watchman watch-del-all`.\n  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.\n  3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.  4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.\n    at ModuleResolver.resolveDependency (/home/t/ws/react/hafas-client-example/example/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:161:1460)\n    at ResolutionRequest.resolveDependency (/home/t/ws/react/hafas-client-example/example/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:91:16)\n    at DependencyGraph.resolveDependency (/home/t/ws/react/hafas-client-example/example/node_modules/metro/src/node-haste/DependencyGraph.js:272:4579)\n    at dependencies.map.relativePath (/home/t/ws/react/hafas-client-example/example/node_modules/metro/src/DeltaBundler/traverseDependencies.js:376:19)\n    at Array.map (native)\n    at resolveDependencies (/home/t/ws/react/hafas-client-example/example/node_modules/metro/src/DeltaBundler/traverseDependencies.js:374:16)\n    at /home/t/ws/react/hafas-client-example/example/node_modules/metro/src/DeltaBundler/traverseDependencies.js:212:33\n    at Generator.next (<anonymous>)\n    at step (/home/t/ws/react/hafas-client-example/example/node_modules/metro/src/DeltaBundler/traverseDependencies.js:297:313)\n    at /home/t/ws/react/hafas-client-example/example/node_modules/metro/src/DeltaBundler/traverseDependencies.js:297:473"}
processBundleResult
    BundleDownloader.java:266
access$200
    BundleDownloader.java:35
onResponse
    BundleDownloader.java:153
execute
    RealCall.java:135
run
    NamedRunnable.java:32
runWorker
    ThreadPoolExecutor.java:1162
run
    ThreadPoolExecutor.java:636
run
    Thread.java:764

@derhuerst
Copy link
Member

I forgot that node-libs-react-native only fixes Node-builtin modules for react-native, but not Node-builtin globals. So my hafas-client@next + node-libs-react-native proposal did't make sense.

Unable to resolve module stream from /home/t/ws/react/hafas-client-example/example/node_modules/cipher-base/index.js: Module stream does not exist in the Haste module map

Did you use node-libs-react-native? Please do this.

@guitar9
Copy link
Author

guitar9 commented Jun 11, 2018

ok i have added it. Now i get Unrecognized token '?'. If i now comment out 'Accept-Encoding': 'gzip, deflate' i get that special case that it works in debug mode but in normal mode not.

If dont comment out 'Accept-Encoding': 'gzip, deflate' i get in normal mode this error: Unrecognized token '?' and in debug mode: Unrecognized token in JSON at postion 0

@derhuerst
Copy link
Member

Can you log the response by and send it? The appropriate place would be here:

return res.json()

You can log the response like this:

	return fetch(url, req)
	.then((res) => {
		err.statusCode = res.status
		if (!res.ok) {
			err.message = res.statusText
			throw err
		}
		return res.text()
	})
	.then((raw) => {
		console.error(raw)
		return JSON.parse(raw)
	})
	.then((b) => {

@guitar9
Copy link
Author

guitar9 commented Jun 12, 2018

In debug mode

Request
{"method":"post","body":"{\"lang\":\"en\",\"svcReqL\":[{\"cfg\":{\"polyEnc\":\"GPA\"},\"meth\":\"TripSearch\",\"req\":{\"outDate\":\"20180612\",\"outTime\":\"111425\",\"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-Encoding":"gzip, deflate","Accept":"application/json","user-agent":"https://github.com/public-transport/hafas-client"},"query":{"checksum":"1499ad9d437497e8f1c8e9e53b5b011d"}}

Response

�����������[[S����+*��9U����b����H���l'{+��K#��,y%����o�c�gF7�����d�N���F=�u��7�v>��<�wt�
Y��o2�9h�� ��¯��,��N�����f�`��.�7#gH)�Ǒ��;�u7�8i���q�B���THпl����鉾��g}ȳ�t�`��,q�B�$)�Nx����q$Za��C���.�k�~�+r�<���}�_Y�����i��a��K�D���޻]��;�?
�[d�f�&#�k�������i��������<�b�\�<J3�����
�O�y����f�9tK��;R���-�������C�y'<Q�A@w��6Xj�
�?�6L�e	�ʒ1�[��4;�]���l-6������ȭ``ܨ�`��B�[�������K�;61K����c�/����<�'_���BK��r
�7�>7(����,q�)�B�2�Ա
R�Ɔ�x�n���po��4��$`j!�.�������r9�����/A
S[�p���?
)A�(�^����M�<�-����&�Ӌz�p.啨��e�<����eM��.����Ğ��r���l��}�mW0 �\!����Q>����n��,�Ʌ�	��n�����,s�����eY{���U7B���;�϶�l����z�Rd �¼a��Ȳ����N/u"5|���<����:>2����>Z�G���#��
���S��K�sj�:>��
�S��L�s^�_���}7��{���Cs�"�)51��
N�Q"�4� �n����
∅�idŨ�����0�@3�Ԗ��?�Z)��Q��:^�Z��h
[��@p595!5ty��������A��9�(���	��y誤�ZO�y�FbdQ���L��E�Q�T��p���%�x=�Mq�AS����ZS����bx�j|.p_`V����Q�@��-�x����Mv��Ϥ�����;qC�jn�]�	�0����t��9���$[�d%��B���
�iـk��
��̑�C�H�����3����.g� �
Y�jq�N���*!x���8��:���4e�v����g1�!����A�?���� ���W�5�>m��Wa�Iւ����fe#d���#�r͏������� Yd��7�UH�� �3o��q�nӘ��4e�~"F`�����ʽڿ�+���6�R�ԥ�.�j��R��;F(�d����Aj3�~���g����<ٿ�b�q,˒�~���L_ ��>��Z����s(�|��R�2�!���x�p��Е�bk��۞�
����Bb�{c�+��71��\��2=`�Y�����X��?�����J���#>���x|��M�����`��s�8�睇,��EI,�Q�HJ�^��s�!,��׮zj��wگ����������)�XB�b�3���՜B��뀡�ʉmAs@��̬��#9���L�,Ѕ-�%�����t�k�p�6״.�D����2��-��Szk�:�-������q)�M���~��g�TUA$�c��΅�ӎ;臅�~����f[��ݴ$c�!�%�(��f7�����\\�jzl�agos~d���Êe,|V��h�Ȓ77Ѧ*_N�N��T�'�
��R�M������W`h��"��wry�_��.��,d���0=�f�q?u�Y�����kτ��A���U�Y»<S��7���������{,	|Q��}�k80	b�O���~�H�1�*��ң$��'����Y�r�׌�����"R���(�aX����q��ť������g2qЅO��,���*��b8��pt�1����/XF�X�[xA�e�g����#��ڍ���3����~�{�D�
�͖�q �Hy��,"t��pռ��-���pN��m�wy�߅���k�e;*c
���zw�������.�Q�;j��Xd{�YU��`?�2�2L䐾�_byZ(���-�ժ���J��"�j�.z��BP�B�e�bߡ��e�wm�%���
rK�s0�q�)��y�ʼn�cѰS'�� �����`�5
�����p�w����y�Z�3<|�i����wz���5���ѷms�u�Rօ��G`�Z��W�<3���JO�������N�F^6�]�oY�k8����\\���<�~@΅�!e2Fל���������j=?;�������璿��"�"
�*i�wH�|�D
�Z,%���0_6�]�p��&YTm&5�}Ó$u�?Z���u�0��p֬����f��`�r=?;�2��
��3�K�ח�oe]�.��vk��7�.ͷg��:���ŤA���ɩZ(]��γ�j��n�Y�D�M�"���p�A���=\y��\�&����c�fR�.�8�ů$�D���DHV��P�}
=̇�1å�l���M��ʸpL`�Eqa��Á<��DZ/H�P���`"k�����)�S�Y�u���1x��;[�vv��՝}�����v���Q�聿�X|T����kt��Q�~ۗB��-f9�|�~��tݤ)Ui7oO{��m`����/�����!�T���������9�h�ߞ��ٰ��<÷�o��bf6@��u�>����@�ُ��G��	��8ť>;�6����!��&Cv����}T�}�����H������(dQ����Ďݠ�!���ŗ������];��

Not in debug mode

Request:
{"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-Encoding":"gzip, deflate","Accept":"application/json","user-agent":"https://github.com/public-transport/hafas-client"},"query":{"checksum":"0d8186da7b06f9cc094075a2a6e21b00"}}

Response:

Error:
JSON Parse Error: Unrecongnized token "?"

@derhuerst
Copy link
Member

This is with Accept-Encoding: gzip?

@guitar9
Copy link
Author

guitar9 commented Jun 13, 2018

with Accept-Encoding': 'gzip, deflate',

@guitar9
Copy link
Author

guitar9 commented Jun 24, 2018

problem was package luxon.

@derhuerst
Copy link
Member

I've had a look into this once more.

I successfully ran [email protected] – installed via npm i hafas-client@next – on the device and managed to fetch departures. I added node-libs-react-native to the config and used the global shims. Will add a notice about this to the readme.

I assume all other errors are related to specifics of your local setup. I'm willing to help debug this, but only with comprehensive info.

derhuerst added a commit that referenced this issue Jun 25, 2018
Hopefully prevents situations like in #56 in the future.

#56 (comment)
@derhuerst
Copy link
Member

I will close this. Please reopen with more details if you still have issues.

@soldatos
Copy link

Hello @derhuerst
i am really desperate. Do you have a branch for react-native version? I can't get node-libs-react-native to integrate.
Thank you

@bergmannjg
Copy link
Contributor

Hi @soldatos,

please have a look at FahrplanApp for an example of hafas-client with react native.

@derhuerst
Copy link
Member

I can't provide a known-working version, sorry; react-native is not a priority for me, and setting it up is just too much of a hassle. I have googled a bit™ though:

As of version 6.0.0, hafas-client makes use of the following dependencies (this is similar with hafas-client@5) that are not self-contained environment-independent JS:

It also uses the following Node builtins:

  • assert – should be easy to mock
  • crypto
  • fs – used in p/{kvb,sncb,ivb}/index.js in order to load SSL certificates, so if you don't use those profiles, you should be fine
  • https
  • module – not sure how to polyfill it
  • net – not sure how to polyfill it, but only isIP is being used from it
  • util – should be easy to mock
  • zlib – not sure how to polyfill it

@derhuerst
Copy link
Member

[…] have a look at FahrplanApp for an example of hafas-client with react native.

Specifically, the shims/polyfills are defined here: https://github.com/bergmannjg/FahrplanApp/blob/a11b4272ff4623f7d015b1491ad5c2297d180dfa/metro.config.js#L24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants