@@ -723,18 +723,7 @@ function createQueryAction (endpoint, responseAction, errorAction, options = {})
723
723
return async function ( dispatch , getState ) {
724
724
const state = getState ( )
725
725
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 )
738
727
739
728
if ( ! options . noThrottle ) {
740
729
// 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 = {})
750
739
throttledUrls [ throttleKey ] = now ( )
751
740
}
752
741
}
742
+
753
743
let payload
754
744
try {
755
- const response = await fetch ( url , options . fetchOptions )
745
+ const response = await fetch ( url , getOtpFetchOptions ( state ) )
756
746
if ( response . status >= 400 ) {
757
747
const error = new Error ( 'Received error from server' )
758
748
error . response = response
@@ -775,6 +765,30 @@ function createQueryAction (endpoint, responseAction, errorAction, options = {})
775
765
}
776
766
}
777
767
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
+
778
792
// TODO: Determine how we might be able to use GraphQL with the alternative
779
793
// transit index. Currently this is not easily possible because the alternative
780
794
// transit index does not have support for GraphQL and handling both Rest and
0 commit comments