From fb115279b6e80890fd9dfd1f6cf794f3a5629fa5 Mon Sep 17 00:00:00 2001 From: kyteinsky Date: Tue, 2 Jun 2026 14:45:16 +0200 Subject: [PATCH] fix: add AsyncResponse type to niquests response object Signed-off-by: kyteinsky --- nc_py_api/_exceptions.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/nc_py_api/_exceptions.py b/nc_py_api/_exceptions.py index c7524bfe..d2f5a39f 100644 --- a/nc_py_api/_exceptions.py +++ b/nc_py_api/_exceptions.py @@ -1,6 +1,6 @@ """Exceptions for the Nextcloud API.""" -from niquests import HTTPError, Response +from niquests import AsyncResponse, HTTPError, Response class NextcloudException(Exception): @@ -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 @@ -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``.