Skip to content

Commit

Permalink
Improve error handling in searchDoi queries with more robust error me…
Browse files Browse the repository at this point in the history
…ssage generation
  • Loading branch information
jrhoads committed Feb 4, 2025
1 parent f485ff9 commit 96e019b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/data/queries/searchDoiFacetsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@ export async function fetchDoisFacets(variables: QueryVar) {
options
)
const json = await res.json()
if(!res.ok) throw new Error(json.errors.title)
if(!res.ok) {
const errorMessage = json?.errors?.title || `Request for facets failed with status: ${res.status}`;
throw new Error(errorMessage);
}

const data = convertToQueryData(json)
return { data }
const data = convertToQueryData(json)
return { data }
}

export function useSearchDoiFacetsQuery(variables: QueryVar) {
Expand Down
9 changes: 6 additions & 3 deletions src/data/queries/searchDoiQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ export async function fetchDois(variables: QueryVar) {
)
const json = await res.json()

if(!res.ok) throw new Error(json.errors.title)
if(!res.ok) {
const errorMessage = json?.errors?.title || `Request for dois failed with status: ${res.status}`;
throw new Error(errorMessage);
}

const data = convertToQueryData(json)
return { data }
const data = convertToQueryData(json)
return { data }
}


Expand Down

0 comments on commit 96e019b

Please sign in to comment.