Skip to content

Commit 097f809

Browse files
authored
Merge pull request #264 from opentripplanner/dev
Bug fix release
2 parents 7fbcb6a + 822b618 commit 097f809

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

lib/components/form/error-message.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
33
import { connect } from 'react-redux'
44
import TripTools from '../narrative/trip-tools'
55

6-
import { getActiveErrors } from '../../util/state'
6+
import { getActiveError } from '../../util/state'
77

88
class ErrorMessage extends Component {
99
static propTypes = {
@@ -46,7 +46,7 @@ class ErrorMessage extends Component {
4646

4747
const mapStateToProps = (state, ownProps) => {
4848
return {
49-
error: getActiveErrors(state.otp)[0],
49+
error: getActiveError(state.otp),
5050
currentQuery: state.otp.currentQuery,
5151
errorMessages: state.otp.config.errorMessages
5252
}

lib/components/mobile/results-screen.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { MobileScreens, setMobileScreen } from '../../actions/ui'
1717
import { setUseRealtimeResponse } from '../../actions/narrative'
1818
import { clearActiveSearch } from '../../actions/form'
1919
import {
20-
getActiveErrors,
20+
getActiveError,
2121
getActiveItineraries,
2222
getActiveSearch,
2323
getRealtimeEffects
@@ -244,7 +244,7 @@ const mapStateToProps = (state, ownProps) => {
244244
return {
245245
query: state.otp.currentQuery,
246246
realtimeEffects,
247-
error: getActiveErrors(state.otp)[0],
247+
error: getActiveError(state.otp),
248248
resultCount:
249249
response
250250
? activeSearch.query.routingType === 'ITINERARY'

lib/components/narrative/narrative-itineraries.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import DefaultItinerary from './default/default-itinerary'
1616
import Icon from '../narrative/icon'
1717
import LinkButton from '../user/link-button'
1818
import {
19-
getActiveErrors,
19+
getResponsesWithErrors,
2020
getActiveItineraries,
2121
getActiveSearch,
2222
getRealtimeEffects
@@ -254,7 +254,7 @@ const mapStateToProps = (state, ownProps) => {
254254
const useRealtime = state.otp.useRealtime
255255
return {
256256
activeSearch,
257-
errors: getActiveErrors(state.otp),
257+
errors: getResponsesWithErrors(state.otp),
258258
// swap out realtime itineraries with non-realtime depending on boolean
259259
itineraries,
260260
pending,

lib/components/narrative/narrative-routing-results.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import TabbedItineraries from './tabbed-itineraries'
77
import ErrorMessage from '../form/error-message'
88

99
import {
10-
getActiveErrors,
10+
getActiveError,
1111
getActiveItineraries,
1212
getActiveSearch
1313
} from '../../util/state'
@@ -51,7 +51,7 @@ const mapStateToProps = (state, ownProps) => {
5151
const pending = activeSearch ? Boolean(activeSearch.pending) : false
5252
return {
5353
mainPanelContent: state.otp.ui.mainPanelContent,
54-
error: getActiveErrors(state.otp)[0],
54+
error: getActiveError(state.otp),
5555
itineraries: getActiveItineraries(state.otp),
5656
pending,
5757
routingType: activeSearch && activeSearch.query.routingType

lib/util/state.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,32 @@ export function getTimestamp (time = moment()) {
2525
}
2626

2727
/**
28-
* Gets the active errors returned for the OTP responses.
28+
* Gets the OTP responses that contain errors. For batch routing this could be
29+
* an array of multiple responses, but for standard itinerary routing it will be
30+
* at most an array with one response.
2931
* @param {Object} otpState the OTP state object
30-
* @return {Array} array of OTP plan responses with errors
32+
* @return {Array} array of OTP plan responses that contain errors
3133
*/
32-
export function getActiveErrors (otpState) {
34+
export function getResponsesWithErrors (otpState) {
3335
const search = getActiveSearch(otpState)
34-
const errors = []
36+
const errorResponses = []
3537
const response = !search ? null : search.response
3638
if (response) {
3739
response.forEach(res => {
38-
if (res && res.error) errors.push(res)
40+
if (res && res.error) errorResponses.push(res)
3941
})
4042
}
41-
return errors
43+
return errorResponses
44+
}
45+
46+
/**
47+
* Gets the active error (first OTP plan response that contains an error). Only
48+
* one OTP response is expected in itinerary routing, but if batch routing is
49+
* enabled, multiple responses with errors should be handled.
50+
*/
51+
export function getActiveError (otpState) {
52+
const errorResponse = getResponsesWithErrors(otpState)[0]
53+
if (errorResponse && errorResponse.error) return errorResponse.error
4254
}
4355

4456
/**

0 commit comments

Comments
 (0)