Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/components/form/error-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import TripTools from '../narrative/trip-tools'

import { getActiveErrors } from '../../util/state'
import { getActiveError } from '../../util/state'

class ErrorMessage extends Component {
static propTypes = {
Expand Down Expand Up @@ -46,7 +46,7 @@ class ErrorMessage extends Component {

const mapStateToProps = (state, ownProps) => {
return {
error: getActiveErrors(state.otp)[0],
error: getActiveError(state.otp),
currentQuery: state.otp.currentQuery,
errorMessages: state.otp.config.errorMessages
}
Expand Down
4 changes: 2 additions & 2 deletions lib/components/mobile/results-screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { MobileScreens, setMobileScreen } from '../../actions/ui'
import { setUseRealtimeResponse } from '../../actions/narrative'
import { clearActiveSearch } from '../../actions/form'
import {
getActiveErrors,
getActiveError,
getActiveItineraries,
getActiveSearch,
getRealtimeEffects
Expand Down Expand Up @@ -244,7 +244,7 @@ const mapStateToProps = (state, ownProps) => {
return {
query: state.otp.currentQuery,
realtimeEffects,
error: getActiveErrors(state.otp)[0],
error: getActiveError(state.otp),
resultCount:
response
? activeSearch.query.routingType === 'ITINERARY'
Expand Down
4 changes: 2 additions & 2 deletions lib/components/narrative/narrative-itineraries.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import DefaultItinerary from './default/default-itinerary'
import Icon from '../narrative/icon'
import LinkButton from '../user/link-button'
import {
getActiveErrors,
getResponsesWithErrors,
getActiveItineraries,
getActiveSearch,
getRealtimeEffects
Expand Down Expand Up @@ -254,7 +254,7 @@ const mapStateToProps = (state, ownProps) => {
const useRealtime = state.otp.useRealtime
return {
activeSearch,
errors: getActiveErrors(state.otp),
errors: getResponsesWithErrors(state.otp),
// swap out realtime itineraries with non-realtime depending on boolean
itineraries,
pending,
Expand Down
4 changes: 2 additions & 2 deletions lib/components/narrative/narrative-routing-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import TabbedItineraries from './tabbed-itineraries'
import ErrorMessage from '../form/error-message'

import {
getActiveErrors,
getActiveError,
getActiveItineraries,
getActiveSearch
} from '../../util/state'
Expand Down Expand Up @@ -51,7 +51,7 @@ const mapStateToProps = (state, ownProps) => {
const pending = activeSearch ? Boolean(activeSearch.pending) : false
return {
mainPanelContent: state.otp.ui.mainPanelContent,
error: getActiveErrors(state.otp)[0],
error: getActiveError(state.otp),
itineraries: getActiveItineraries(state.otp),
pending,
routingType: activeSearch && activeSearch.query.routingType
Expand Down
24 changes: 18 additions & 6 deletions lib/util/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,32 @@ export function getTimestamp (time = moment()) {
}

/**
* Gets the active errors returned for the OTP responses.
* Gets the OTP responses that contain errors. For batch routing this could be
* an array of multiple responses, but for standard itinerary routing it will be
* at most an array with one response.
* @param {Object} otpState the OTP state object
* @return {Array} array of OTP plan responses with errors
* @return {Array} array of OTP plan responses that contain errors
*/
export function getActiveErrors (otpState) {
export function getResponsesWithErrors (otpState) {
const search = getActiveSearch(otpState)
const errors = []
const errorResponses = []
const response = !search ? null : search.response
if (response) {
response.forEach(res => {
if (res && res.error) errors.push(res)
if (res && res.error) errorResponses.push(res)
})
}
return errors
return errorResponses
}

/**
* Gets the active error (first OTP plan response that contains an error). Only
* one OTP response is expected in itinerary routing, but if batch routing is
* enabled, multiple responses with errors should be handled.
*/
export function getActiveError (otpState) {
const errorResponse = getResponsesWithErrors(otpState)[0]
if (errorResponse && errorResponse.error) return errorResponse.error
}

/**
Expand Down