Skip to content

Commit

Permalink
Merge pull request #56 from nasa-petal/ss-search-error
Browse files Browse the repository at this point in the history
Fix Semantic Scholar Outage causing unrecoverable error
  • Loading branch information
bruffridge authored Mar 6, 2024
2 parents 396aaf1 + dbaf5f5 commit 8b9e430
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/assistant/bidaraFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,22 @@ export async function ssSearch(params) {
fields = [...new Set(fields)]; //remove duplicates
searchParams.fields = fields.join();
searchParams = new URLSearchParams(searchParams);
const response = await fetch("https://api.semanticscholar.org/graph/v1/paper/search?" + searchParams);
const papers = await response.json();
return JSON.stringify(papers);

try {
const response = await fetch("https://api.semanticscholar.org/graph/v1/paper/search?" + searchParams);

if (response.status === 429) {
return "Semantic Scholar is currently having issues with their servers. So, for now, searching for academic papers will not work."
}
const papers = await response.json();
return JSON.stringify(papers);
} catch (e) {
if (e instanceof TypeError && e.message === 'Failed to fetch') {
return "Semantic Scholar is currently having issues with their servers. So, for now, searching for academic papers will not work."
}

throw e;
}
}

async function genImage(params) {
Expand Down

0 comments on commit 8b9e430

Please sign in to comment.