Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions nc_py_api/_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Exceptions for the Nextcloud API."""

from niquests import HTTPError, Response
from niquests import AsyncResponse, HTTPError, Response
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Is AsyncResponse exported from the top-level niquests package (e.g. from niquests import AsyncResponse)? What niquests version added it?

💡 Result:

Yes. Niquests exports AsyncResponse from the top-level package, so from niquests import AsyncResponse works, as reflected in Niquests’ API documentation which lists AsyncResponse as an autoclass in the main API docs alongside the top-level interface. [1] Version: I could not find a specific release note/tag that explicitly states “exported AsyncResponse” or the version where AsyncResponse was introduced. However, Niquests’ HISTORY notes that AsyncSession “now returns a AsyncResponse when stream is set to True” (i.e., the async streaming response type existed by the time of that change), but the HISTORY snippet retrieved does not include the version number for that change. [2]

Citations:


_exceptions.py: from niquests import AsyncResponse appears to be a supported top-level export—Niquests’ API docs list AsyncResponse for the main package namespace, so this import should resolve. Since no exact “introduced in version X” release note was found, consider pinning a specific niquests version (or adding a fallback import) to avoid an ImportError if older 3.x releases ever lacked the re-export.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@nc_py_api/_exceptions.py` at line 3, The import may fail on older niquests
releases because AsyncResponse may not be re-exported; update the code to handle
that by adding a fallback import or pinning niquests: either pin niquests to a
version known to export AsyncResponse in your dependency manifest, or modify the
import in _exceptions.py to try the current top-level import of AsyncResponse,
HTTPError, Response and on ImportError fall back to the module path that
actually defines AsyncResponse (e.g., the internal async submodule) so the
symbols AsyncResponse, HTTPError, and Response are always available.



class NextcloudException(Exception):
Expand All @@ -9,9 +9,15 @@ class NextcloudException(Exception):
status_code: int
reason: str
info: str
response: Response | None

def __init__(self, status_code: int = 0, reason: str = "", info: str = "", response: Response | None = None):
response: AsyncResponse | Response | None

def __init__(
self,
status_code: int = 0,
reason: str = "",
info: str = "",
response: AsyncResponse | Response | None = None,
):
super(BaseException, self).__init__()
self.status_code = status_code
self.reason = reason
Expand All @@ -27,25 +33,25 @@ def __str__(self):
class NextcloudExceptionNotModified(NextcloudException):
"""The exception indicates that there is no need to retransmit the requested resources."""

def __init__(self, reason="Not modified", info: str = "", response: Response | None = None):
def __init__(self, reason="Not modified", info: str = "", response: AsyncResponse | Response | None = None):
super().__init__(304, reason=reason, info=info, response=response)


class NextcloudExceptionNotFound(NextcloudException):
"""The exception that is thrown during operations when the object is not found."""

def __init__(self, reason="Not found", info: str = "", response: Response | None = None):
def __init__(self, reason="Not found", info: str = "", response: AsyncResponse | Response | None = None):
super().__init__(404, reason=reason, info=info, response=response)


class NextcloudMissingCapabilities(NextcloudException):
"""The exception that is thrown when required capability for API is missing."""

def __init__(self, reason="Missing capability", info: str = "", response: Response | None = None):
def __init__(self, reason="Missing capability", info: str = "", response: AsyncResponse | Response | None = None):
super().__init__(412, reason=reason, info=info, response=response)


def check_error(response: Response, info: str = ""):
def check_error(response: AsyncResponse | Response, info: str = ""):
"""Checks HTTP code from Nextcloud, and raises exception in case of error.

For the OCS and DAV `code` be code returned by HTTP and not the status from ``ocs_meta``.
Expand Down
Loading