Skip to content

Commit

Permalink
fix: better network request error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
stdavis committed Mar 25, 2024
1 parent 20c3ebc commit 7ee4080
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
21 changes: 15 additions & 6 deletions src/scripts/utilities.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,21 @@ export async function validateOpenDataUrl(url) {
org = domainToOrg[domain];
}
const openDataQuery = 'https://opendata.arcgis.com/api/v3/datasets';
const response = await ky(openDataQuery, {
searchParams: {
'fields[datasets]': 'slug,boundary,extent,recordCount,searchDescription,statistics',
'filter[slug]': `${org}::${slug}`,
},
}).json();

let response;
try {
response = await ky(openDataQuery, {
searchParams: {
'fields[datasets]': 'slug,boundary,extent,recordCount,searchDescription,statistics',
'filter[slug]': `${org}::${slug}`,
},
}).json();
} catch (error) {
return {
valid: false,
message: `request error: ${error.message}`,
};
}

if (response.data.length === 0) {
return {
Expand Down
13 changes: 9 additions & 4 deletions src/scripts/validate-sgid-index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { validateOpenDataUrl, validateOpenSgidTableName, validateUrl } from './u
const downloadMetadata = await tsImport.load('../data/downloadMetadata.ts');

const spreadsheetId = '11ASS7LnxgpnD0jN4utzklREgMf1pcvYjcXcIcESHweQ';
const ourWebSite = 'https://gis-utah.netlify.app';

const scopes = ['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive'];
let client;
Expand Down Expand Up @@ -68,7 +69,7 @@ async function productPage(row) {
return;
}

const url = cellValue.startsWith('/') ? `https://gis-utah.netlify.app${cellValue}` : cellValue;
const url = cellValue.startsWith('/') ? `${ourWebSite}${cellValue}` : cellValue;

let result = await validateUrl(url);

Expand Down Expand Up @@ -106,9 +107,13 @@ async function itemId(row) {
return;
}

const hubData = await ky(
`https://opendata.arcgis.com/api/v3/datasets/${cellValue}_${row.get('serverLayerId')}`,
).json();
let hubData;
try {
hubData = await ky(`https://opendata.arcgis.com/api/v3/datasets/${cellValue}_${row.get('serverLayerId')}`).json();
} catch (error) {
recordError(`itemId hub request error: ${error.message}`, row);
return;
}
const serviceParts = hubData.data.attributes.url.split('/rest/services/');

const newData = {
Expand Down

0 comments on commit 7ee4080

Please sign in to comment.