Skip to content

Commit

Permalink
Use hubmap's improved search-api response
Browse files Browse the repository at this point in the history
  • Loading branch information
bherr2 committed May 11, 2023
1 parent de5cc39 commit 9cdfc70
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions projects/ccf-database/src/lib/hubmap/hubmap-data-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface SearchResultJson {


// Reduce this value if including more data fields
const PER_API_SEARCH_REQUEST_COUNT = 250;
const PER_API_SEARCH_REQUEST_COUNT = 10000;

const INCLUDED_DATA_FIELDS = [
'uuid', 'entity_type',
Expand Down Expand Up @@ -86,7 +86,16 @@ async function doSearchRequest(
): Promise<SearchResultJson | undefined> {
try {
const res = await fetch(url, init);
return res.ok ? (await res.json()) : undefined;
const text = await res.text();
const validResponse = res.ok || text.startsWith('https');
if (validResponse) {
if (text.startsWith('https')) {
return await fetch(text).then((r) => r.json());
} else {
return JSON.parse(text);
}
}
return undefined;
} catch (_error) {
return undefined;
}
Expand Down

0 comments on commit 9cdfc70

Please sign in to comment.