Skip to content

Commit a0b6f21

Browse files
authored
Merge pull request #418 from opentripplanner/improve-modestr-extraction
Use url query params if response lacks OTP data
2 parents f590d24 + a46c56c commit a0b6f21

File tree

4 files changed

+17
-171
lines changed

4 files changed

+17
-171
lines changed

Diff for: __tests__/actions/__snapshots__/api.js.snap

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Array [
3838
"error": [TypeError: Cannot read property 'trackRecent' of undefined],
3939
"requestId": "abcd1239",
4040
"searchId": "abcd1234",
41+
"url": "http://mock-host.com:80/api/plan?fromPlace=Origin%20%2812%2C34%29%3A%3A12%2C34&toPlace=Destination%20%2834%2C12%29%3A%3A34%2C12&mode=WALK%2CTRANSIT&ignoreRealtimeUpdates=false",
4142
},
4243
"type": "ROUTING_ERROR",
4344
},
@@ -66,6 +67,7 @@ Array [
6667
"error": [Error: Received error from server],
6768
"requestId": "abcd1240",
6869
"searchId": "abcd1237",
70+
"url": "http://mock-host.com:80/api/plan?fromPlace=Origin%20%2812%2C34%29%3A%3A12%2C34&toPlace=Destination%20%2834%2C12%29%3A%3A34%2C12&mode=WALK%2CTRANSIT&ignoreRealtimeUpdates=false",
6971
},
7072
"type": "ROUTING_ERROR",
7173
},
@@ -111,6 +113,7 @@ Array [
111113
"error": [TypeError: Cannot read property 'trackRecent' of undefined],
112114
"requestId": "abcd1236",
113115
"searchId": "abcd1234",
116+
"url": "http://mock-host.com:80/api/plan?fromPlace=Origin%20%2812%2C34%29%3A%3A12%2C34&toPlace=Destination%20%2834%2C12%29%3A%3A34%2C12&mode=WALK%2CTRANSIT&ignoreRealtimeUpdates=false",
114117
},
115118
"type": "ROUTING_ERROR",
116119
},

Diff for: lib/actions/api.js

+4-166
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ export function routingQuery (searchId = null, updateSearchInReducer = false) {
124124
return Promise.all(iterations.map((injectedParams, i) => {
125125
const requestId = randId()
126126
// fetch a realtime route
127-
const query = constructRoutingQuery(state, false, injectedParams)
128-
const realTimeFetch = fetch(query, getOtpFetchOptions(state))
127+
const url = constructRoutingQuery(state, false, injectedParams)
128+
const realTimeFetch = fetch(url, getOtpFetchOptions(state))
129129
.then(getJsonAndCheckResponse)
130130
.then(json => {
131131
const dispatchedRoutingResponse = dispatch(routingResponse({
@@ -143,12 +143,12 @@ export function routingQuery (searchId = null, updateSearchInReducer = false) {
143143
if (!isStoredPlace(to)) {
144144
dispatch(rememberPlace({ location: formatRecentPlace(to), type: 'recent' }))
145145
}
146-
dispatch(rememberSearch(formatRecentSearch(query, state)))
146+
dispatch(rememberSearch(formatRecentSearch(url, state)))
147147
}
148148
return dispatchedRoutingResponse
149149
})
150150
.catch(error => {
151-
dispatch(routingError({ error, requestId, searchId }))
151+
dispatch(routingError({ error, requestId, searchId, url }))
152152
})
153153
// Update OTP URL params if a new search. In other words, if we're
154154
// performing a search based on query params taken from the URL after a back
@@ -328,84 +328,6 @@ export function findStop (params) {
328328
)
329329
}
330330

331-
// TODO: Optionally substitute GraphQL queries? Note: this is not currently
332-
// possible because gtfsdb (the alternative transit index used by TriMet) does not
333-
// support GraphQL queries.
334-
// export function findStop (params) {
335-
// const query = `
336-
// query stopQuery($stopId: [String]) {
337-
// stops (ids: $stopId) {
338-
// id: gtfsId
339-
// code
340-
// name
341-
// url
342-
// lat
343-
// lon
344-
// stoptimesForPatterns {
345-
// pattern {
346-
// id: semanticHash
347-
// route {
348-
// id: gtfsId
349-
// longName
350-
// shortName
351-
// sortOrder
352-
// }
353-
// }
354-
// stoptimes {
355-
// scheduledArrival
356-
// realtimeArrival
357-
// arrivalDelay
358-
// scheduledDeparture
359-
// realtimeDeparture
360-
// departureDelay
361-
// timepoint
362-
// realtime
363-
// realtimeState
364-
// serviceDay
365-
// headsign
366-
// }
367-
// }
368-
// }
369-
// }
370-
// `
371-
// return createGraphQLQueryAction(
372-
// query,
373-
// { stopId: params.stopId },
374-
// findStopResponse,
375-
// findStopError,
376-
// {
377-
// // find stop should not be throttled since it can make quite frequent
378-
// // updates when fetching stop times for a stop
379-
// noThrottle: true,
380-
// serviceId: 'stops',
381-
// rewritePayload: (payload) => {
382-
// // convert pattern array to ID-mapped object
383-
// const patterns = []
384-
// const { stoptimesForPatterns, ...stop } = payload.data.stops[0]
385-
// stoptimesForPatterns.forEach(obj => {
386-
// const { pattern, stoptimes: stopTimes } = obj
387-
// // It's possible that not all stop times for a pattern will share the
388-
// // same headsign, but this is probably a minor edge case.
389-
// const headsign = stopTimes[0]
390-
// ? stopTimes[0].headsign
391-
// : pattern.route.longName
392-
// const patternIndex = patterns.findIndex(p =>
393-
// p.headsign === headsign && pattern.route.id === p.route.id)
394-
// if (patternIndex === -1) {
395-
// patterns.push({ ...pattern, headsign, stopTimes })
396-
// } else {
397-
// patterns[patternIndex].stopTimes.push(...stopTimes)
398-
// }
399-
// })
400-
// return {
401-
// ...stop,
402-
// patterns
403-
// }
404-
// }
405-
// }
406-
// )
407-
// }
408-
409331
// Single trip lookup query
410332

411333
export const findTripResponse = createAction('FIND_TRIP_RESPONSE')
@@ -558,45 +480,6 @@ export function findRoutes (params) {
558480
)
559481
}
560482

561-
// export function findRoutes (params) {
562-
// const query = `
563-
// {
564-
// routes {
565-
// id: gtfsId
566-
// color
567-
// longName
568-
// shortName
569-
// mode
570-
// type
571-
// desc
572-
// bikesAllowed
573-
// sortOrder
574-
// textColor
575-
// url
576-
// agency {
577-
// id: gtfsId
578-
// name
579-
// url
580-
// }
581-
// }
582-
// }
583-
// `
584-
// return createGraphQLQueryAction(
585-
// query,
586-
// {},
587-
// findRoutesResponse,
588-
// findRoutesError,
589-
// {
590-
// serviceId: 'routes',
591-
// rewritePayload: (payload) => {
592-
// const routes = {}
593-
// payload.data.routes.forEach(rte => { routes[rte.id] = rte })
594-
// return routes
595-
// }
596-
// }
597-
// )
598-
// }
599-
600483
// Patterns for Route lookup query
601484
// TODO: replace with GraphQL query for route => patterns => geometry
602485
const findPatternsForRouteResponse = createAction('FIND_PATTERNS_FOR_ROUTE_RESPONSE')
@@ -673,51 +556,6 @@ export function findGeometryForPattern (params) {
673556
)
674557
}
675558

676-
// export function findRoute (params) {
677-
// const query = `
678-
// query routeQuery($routeId: [String]) {
679-
// routes (ids: $routeId) {
680-
// id: gtfsId
681-
// patterns {
682-
// id: semanticHash
683-
// directionId
684-
// headsign
685-
// name
686-
// semanticHash
687-
// geometry {
688-
// lat
689-
// lon
690-
// }
691-
// }
692-
// }
693-
// }
694-
// `
695-
// return createGraphQLQueryAction(
696-
// query,
697-
// { routeId: params.routeId },
698-
// findPatternsForRouteResponse,
699-
// findPatternsForRouteError,
700-
// {
701-
// rewritePayload: (payload) => {
702-
// // convert pattern array to ID-mapped object
703-
// const patterns = {}
704-
// payload.data.routes[0].patterns.forEach(ptn => {
705-
// patterns[ptn.id] = {
706-
// routeId: params.routeId,
707-
// patternId: ptn.id,
708-
// geometry: ptn.geometry
709-
// }
710-
// })
711-
//
712-
// return {
713-
// routeId: params.routeId,
714-
// patterns
715-
// }
716-
// }
717-
// }
718-
// )
719-
// }
720-
721559
// TNC ETA estimate lookup query
722560

723561
export const transportationNetworkCompanyEtaResponse = createAction('TNC_ETA_RESPONSE')

Diff for: lib/reducers/create-otp-reducer.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ function createOtpReducer (config) {
299299
response: {
300300
$push: [{
301301
error: action.payload.error,
302-
requestId
302+
requestId,
303+
url: action.payload.url
303304
}]
304305
}
305306
}

Diff for: lib/util/state.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import isEqual from 'lodash.isequal'
33
import memoize from 'lodash.memoize'
44
import moment from 'moment'
55
import hash from 'object-hash'
6+
import qs from 'qs'
67
import { createSelector } from 'reselect'
78

89
import { MainPanelContent } from '../actions/ui'
@@ -93,16 +94,19 @@ export function getResponsesWithErrors (state) {
9394
response.forEach(res => {
9495
if (res) {
9596
if (res.error) {
97+
const params = qs.parse(res.url)
98+
const modeStr = res.requestParameters?.mode || params.mode || ''
9699
let msg = res.error.msg || 'An error occurred while planning a trip'
97100
// include the modes if doing batch routing
98-
if (showModes && res.requestParameters?.mode) {
99-
const mode = humanReadableMode(res.requestParameters.mode)
101+
if (showModes && modeStr) {
102+
const mode = humanReadableMode(modeStr)
100103
msg = `No trip found for ${mode}. ${msg.replace(/^No trip found. /, '')}`
101104
}
102105
tripPlanningErrors.push({
103106
id: res.error.id,
104-
modes: res.requestParameters?.mode?.split(','),
105-
msg
107+
modes: modeStr.split(','),
108+
msg,
109+
url: res.url
106110
})
107111
}
108112
const feedWideRentalErrors = getFeedWideRentalErrors(res)

0 commit comments

Comments
 (0)