fix(frontend): robust error handling in fetchers and fix UUID casting

This commit is contained in:
cawcenter
2025-12-13 22:49:08 -05:00
parent 6add486fe8
commit be0bb9766d

View File

@@ -225,7 +225,7 @@ export async function fetchGeneratedArticleBySlug(
filter: { filter: {
_and: [ _and: [
{ slug: { _eq: slug } }, { slug: { _eq: slug } },
{ site_id: { _eq: Number(siteId) } }, { site_id: { _eq: siteId } },
{ is_published: { _eq: true } } { is_published: { _eq: true } }
] ]
}, },
@@ -270,26 +270,37 @@ export async function fetchCampaigns(siteId?: string) {
* Fetch locations (states, counties, cities) * Fetch locations (states, counties, cities)
*/ */
export async function fetchStates() { export async function fetchStates() {
return directus.request( try {
return await directus.request(
readItems('locations_states', { readItems('locations_states', {
sort: ['name'], sort: ['name'],
fields: ['*'] fields: ['*']
}) })
); );
} catch (err) {
console.error('Error fetching states:', err);
return [];
}
} }
export async function fetchCountiesByState(stateId: string) { export async function fetchCountiesByState(stateId: string) {
return directus.request( try {
return await directus.request(
readItems('locations_counties', { readItems('locations_counties', {
filter: { state: { _eq: stateId } }, filter: { state: { _eq: stateId } },
sort: ['name'], sort: ['name'],
fields: ['*'] fields: ['*']
}) })
); );
} catch (err) {
console.error('Error fetching counties:', err);
return [];
}
} }
export async function fetchCitiesByCounty(countyId: string, limit = 50) { export async function fetchCitiesByCounty(countyId: string, limit = 50) {
return directus.request( try {
return await directus.request(
readItems('locations_cities', { readItems('locations_cities', {
filter: { county: { _eq: countyId } }, filter: { county: { _eq: countyId } },
sort: ['-population'], sort: ['-population'],
@@ -297,4 +308,8 @@ export async function fetchCitiesByCounty(countyId: string, limit = 50) {
fields: ['*'] fields: ['*']
}) })
); );
} catch (err) {
console.error('Error fetching cities:', err);
return [];
}
} }