Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance DOI Search Error Handling #450

Merged
merged 8 commits into from
Feb 4, 2025
Merged

Enhance DOI Search Error Handling #450

merged 8 commits into from
Feb 4, 2025

Conversation

jrhoads
Copy link
Contributor

@jrhoads jrhoads commented Feb 4, 2025

Purpose

Improve error handling and response processing in DOI search and facets queries to provide more informative error messages and ensure proper error propagation.

Approach

The changes enhance the error handling mechanism for DOI search and facets API requests by:

  • Adding explicit error checking for API responses
  • Throwing meaningful error messages when requests fail
  • Ensuring that errors are properly propagated through the query function

Key Modifications

  • Added response status checking in fetchDois and fetchDoisFacets functions
  • Implemented custom error message generation based on API response
  • Removed try-catch blocks in favor of direct error throwing
  • Ensured that error messages include both API-provided error titles and fallback status code messages
  • Standardized the "No results" alert across different search types
  • Removed duplicate error handling code

Important Technical Details

  • Error messages now include more context:
    • API-provided error title
    • Fallback error message with HTTP status code
  • Errors are now thrown instead of being silently returned
  • Query functions will now properly propagate errors to React Query's error handling mechanism
  • Introduced a reusable NoResults component that can be used across different search types

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

The changes improve error handling by providing more transparent and informative error messages during DOI search API requests, making debugging and error tracking more straightforward.

Reviewer, please remember our guidelines:

  • Be humble in the language and feedback you give, ask don't tell.
  • Consider using positive language as opposed to neutral when offering feedback. This is to avoid the negative bias that can occur with neutral language appearing negative.
  • Offer suggestions on how to improve code e.g. simplification or expanding clarity.
  • Ensure you give reasons for the changes you are proposing.

Copy link

cypress bot commented Feb 4, 2025

akita    Run #1537

Run Properties:  status check passed Passed #1537  •  git commit 25de636001 ℹ️: Merge ad7957af7741c3dcfd82ecf025ccfa7f88133ad4 into 8590680c06a38cc7d70616395d7c...
Project akita
Branch Review issue-2286
Run status status check passed Passed #1537
Run duration 01m 50s
Commit git commit 25de636001 ℹ️: Merge ad7957af7741c3dcfd82ecf025ccfa7f88133ad4 into 8590680c06a38cc7d70616395d7c...
Committer Joseph Rhoads
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 3
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 50
View all changes introduced in this branch ↗︎

@@ -23,34 +22,15 @@ export default function SearchOrganizations(props: Props) {

if (loading) return <Row><Loading /></Row>

if (error) return (
const organizations = data?.organizations
if (error || !organizations || organizations.nodes.length == 0) return (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason we may want to keep the granularity of splitting the error out from no results and showing the error component? @jrhoads

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we ever want to in the future, we can split this up again.

options
)
const json = await res.json()
if(!res.ok) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to do the error handling this way on all the REST fetches? @jrhoads

Copy link
Contributor Author

@jrhoads jrhoads Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. We had been catching the error. React/Tanstack query expects an error to be thrown. Otherwise it never populates the error state.

@jrhoads jrhoads merged commit 261cb78 into master Feb 4, 2025
11 of 12 checks passed
@jrhoads jrhoads deleted the issue-2286 branch February 4, 2025 14:49
Copy link

cypress bot commented Feb 4, 2025

akita    Run #1539

Run Properties:  status check passed Passed #1539  •  git commit 261cb78a84: Merge pull request #450 from datacite/issue-2286
Project akita
Branch Review 1.18.1
Run status status check passed Passed #1539
Run duration 02m 00s
Commit git commit 261cb78a84: Merge pull request #450 from datacite/issue-2286
Committer Joseph Rhoads
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 3
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 50
View all changes introduced in this branch ↗︎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants