@@ -723,18 +723,7 @@ function createQueryAction (endpoint, responseAction, errorAction, options = {})
723723 return async function ( dispatch , getState ) {
724724 const state = getState ( )
725725 const { config } = state . otp
726- let url
727- if (
728- options . serviceId &&
729- config . alternateTransitIndex &&
730- config . alternateTransitIndex . services . includes ( options . serviceId )
731- ) {
732- console . log ( 'Using alt service for ' + options . serviceId )
733- url = config . alternateTransitIndex . apiRoot + endpoint
734- } else {
735- const api = config . api
736- url = `${ api . host } ${ api . port ? ':' + api . port : '' } ${ api . path } /${ endpoint } `
737- }
726+ const url = makeApiUrl ( config , endpoint , options )
738727
739728 if ( ! options . noThrottle ) {
740729 // don't make a request to a URL that has already seen the same request
@@ -750,9 +739,10 @@ function createQueryAction (endpoint, responseAction, errorAction, options = {})
750739 throttledUrls [ throttleKey ] = now ( )
751740 }
752741 }
742+
753743 let payload
754744 try {
755- const response = await fetch ( url , options . fetchOptions )
745+ const response = await fetch ( url , getOtpFetchOptions ( state ) )
756746 if ( response . status >= 400 ) {
757747 const error = new Error ( 'Received error from server' )
758748 error . response = response
@@ -775,6 +765,30 @@ function createQueryAction (endpoint, responseAction, errorAction, options = {})
775765 }
776766}
777767
768+ /**
769+ * Creates the URL to use for making an API request.
770+ *
771+ * @param {Object } config The app-wide config
772+ * @param {string } endpoint The API endpoint path
773+ * @param {Object } options The options object for the API request
774+ * @return {string } The URL to use for making the http request
775+ */
776+ function makeApiUrl ( config , endpoint , options ) {
777+ let url
778+ if (
779+ options . serviceId &&
780+ config . alternateTransitIndex &&
781+ config . alternateTransitIndex . services . includes ( options . serviceId )
782+ ) {
783+ console . log ( 'Using alt service for ' + options . serviceId )
784+ url = config . alternateTransitIndex . apiRoot + endpoint
785+ } else {
786+ const api = config . api
787+ url = `${ api . host } ${ api . port ? ':' + api . port : '' } ${ api . path } /${ endpoint } `
788+ }
789+ return url
790+ }
791+
778792// TODO: Determine how we might be able to use GraphQL with the alternative
779793// transit index. Currently this is not easily possible because the alternative
780794// transit index does not have support for GraphQL and handling both Rest and
0 commit comments