Skip to content

Handle Error for Invalid QGIS Hub API Responses#137

Merged
ronitjadhav merged 3 commits intomainfrom
handle-invalid-api-response
Nov 14, 2025
Merged

Handle Error for Invalid QGIS Hub API Responses#137
ronitjadhav merged 3 commits intomainfrom
handle-invalid-api-response

Conversation

@ronitjadhav
Copy link
Collaborator

Description

This PR addresses the issue of handling invalid responses from the QGIS Hub API. It ensures the application gracefully deals with unexpected, missing, or corrupted data so the UI no longer exposes stack traces. The API client now raises a consistent, user-friendly error that identifies the failing base URL, the resource browser surfaces that message, and new unit tests cover both corrupted cache files and download failures to guard against regressions.

Screenshot

image

fix #94

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves error handling for QGIS Hub API connectivity issues by replacing raw exceptions with user-friendly error messages.

Key changes:

  • Wraps JSON decode errors and download errors in a custom DownloadError exception with a consistent user-friendly message
  • Adds exception handling in the GUI layer to gracefully display errors to users
  • Updates test cases to verify the new error handling behavior

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
qgis_hub_plugin/core/api_client.py Refactors error handling to wrap JSON decode and download errors with user-friendly messages, extracts JSON loading logic into _load_response helper function
qgis_hub_plugin/gui/resource_browser.py Adds try-except block to catch DownloadError and display user-friendly error message in the UI
tests/qgis/test_api_client_mocked.py Updates test to verify DownloadError is raised with correct message instead of raw JSONDecodeError, adds new test for download error handling
Comments suppressed due to low confidence (1)

qgis_hub_plugin/gui/resource_browser.py:243

  • This check for response is None is now unreachable. The refactored get_all_resources function in api_client.py always raises DownloadError instead of returning None when it fails (line 41 of api_client.py). This code path can never execute and should be removed.
            if response is None:
                self.show_warning_message("Error populating the resources")
                return

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 11 to 12
Copy link

Copilot AI Nov 9, 2025

Choose a reason for hiding this comment

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

The f-strings here are unnecessary since there are no variable interpolations. The BASE_URL is only included as literal text in parentheses. Consider using a regular string or a simple concatenation: API_UNAVAILABLE_MESSAGE = \"Unable to reach the QGIS Hub API. Please check the QGIS Hub API status and try again. (\" + BASE_URL + \")\"

Suggested change
f"Unable to reach the QGIS Hub API. "
f"Please check the QGIS Hub API status and try again. ({BASE_URL})"
"Unable to reach the QGIS Hub API. "
"Please check the QGIS Hub API status and try again. (" + BASE_URL + ")"

Copilot uses AI. Check for mistakes.
@ismailsunni
Copy link
Collaborator

Can you make the link clickable? So that user can try to cilck it directly and see if there is an error in the server.

@ronitjadhav
Copy link
Collaborator Author

The link should be clickable now.

@ismailsunni
Copy link
Collaborator

Is it ready to be reviewed @ronitjadhav ?

@ronitjadhav
Copy link
Collaborator Author

Yes it is ready 👍🏼

@ronitjadhav ronitjadhav merged commit f2a636f into main Nov 14, 2025
4 checks passed
@ronitjadhav ronitjadhav deleted the handle-invalid-api-response branch November 14, 2025 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle Error when the Response from QGIS Hub API is invalid

2 participants

Comments