1- import { HYDROCRON_URL } from '@/constants'
1+ import { ENDPOINTS } from '@/constants'
22import { useFeaturesStore } from '@/stores/features'
33import { useAlertStore } from '@/stores/alerts'
44import { useHydrologicStore } from '@/stores/hydrologic'
@@ -87,6 +87,12 @@ const queryHydroCron = async (swordFeature = null, output = 'geojson') => {
8787 const start_time = EARLIEST_HYDROCRON_DATETIME
8888 const end_time = new Date ( Date . now ( ) + MS_TO_KEEP_CACHE ) . toISOString ( ) . split ( '.' ) [ 0 ] + 'Z'
8989
90+ // determine which collection name to use based on feature type ('Reach' or 'PriorLake')
91+ let collection_name = 'SWOT_L2_HR_RiverSP_D'
92+ if ( feature_type === 'PriorLake' ) {
93+ collection_name = 'SWOT_L2_HR_LakeSP_D'
94+ }
95+
9096 params = {
9197 feature : feature_type ,
9298 feature_id,
@@ -95,9 +101,15 @@ const queryHydroCron = async (swordFeature = null, output = 'geojson') => {
95101 output,
96102 fields,
97103 // https://podaac.github.io/hydrocron/timeseries.html#compact-string-required-no
98- compact : 'true'
104+ compact : 'true' ,
105+ // https://podaac.github.io/hydrocron/timeseries.html#collection-name-string-required-no
106+ collection_name
99107 }
100- let response = await fetchHydroCronData ( HYDROCRON_URL , params , swordFeature )
108+
109+ // Use our API proxy URL instead of the direct HydroCron URL
110+ // This is due to CORS issues with the HydroCron server
111+ // https://github.com/podaac/hydrocron/issues/306
112+ let response = await fetchHydroCronData ( ENDPOINTS . hydrocron , params , swordFeature )
101113 if ( response == null ) {
102114 return
103115 }
@@ -134,19 +146,31 @@ const fetchHydroCronData = async (url, params, swordFeature) => {
134146 } )
135147 if ( response . status < 500 ) {
136148 if ( response . status == 400 ) {
149+ let text = 'No data found for: '
150+ if ( params . feature && params . feature_id ) {
151+ text += `${ params . feature } ${ params . feature_id } `
152+ } else {
153+ text += JSON . stringify ( params )
154+ }
137155 alertStore . displayAlert ( {
138156 title : 'No data found' ,
139- text : `No data found for ${ JSON . stringify ( params ) } ` ,
157+ text,
140158 type : 'warning' ,
141159 closable : true ,
142160 duration : 6
143161 } )
144162 return null
145163 }
146164 } else {
165+ let text = 'Error while fetching SWOT data: '
166+ if ( response . statusText ) {
167+ text += response . statusText
168+ } else {
169+ text += 'Unknown error'
170+ }
147171 alertStore . displayAlert ( {
148172 title : 'Error fetching SWOT data' ,
149- text : `Error while fetching SWOT data: ${ response . statusText } ` ,
173+ text,
150174 type : 'error' ,
151175 closable : true ,
152176 duration : 3
0 commit comments