Skip to content

Commit a343e7f

Browse files
fix: add AsyncResponse type to niquests response object (#439)
Changes proposed in this pull request: * the object returned by niquests in the response can be `AsyncResponse` (child class of `Response`: https://github.com/jawah/niquests/blob/6dc75e944c41551a90ccabf08a203f1a719ce87b/src/niquests/models.py#L1660) if the request calls were made async-ly: https://github.com/jawah/niquests/blob/6dc75e944c41551a90ccabf08a203f1a719ce87b/src/niquests/async_session.py#L1150-L1182 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Updated error handling to work consistently with both synchronous and asynchronous response objects, including broader support in the core exception classes and `check_error`. * **Chores** * Tightened the minimum supported `niquests` version requirement to `3.4.2` (still under the same major-version cap). <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: kyteinsky <kyteinsky@gmail.com> Signed-off-by: Oleksandr Piskun <oleksandr2088@icloud.com> Co-authored-by: Oleksandr Piskun <oleksandr2088@icloud.com>
1 parent 55e120c commit a343e7f

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

nc_py_api/_exceptions.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Exceptions for the Nextcloud API."""
22

3-
from niquests import HTTPError, Response
3+
from niquests import AsyncResponse, HTTPError, Response
44

55

66
class NextcloudException(Exception):
@@ -9,9 +9,15 @@ class NextcloudException(Exception):
99
status_code: int
1010
reason: str
1111
info: str
12-
response: Response | None
13-
14-
def __init__(self, status_code: int = 0, reason: str = "", info: str = "", response: Response | None = None):
12+
response: AsyncResponse | Response | None
13+
14+
def __init__(
15+
self,
16+
status_code: int = 0,
17+
reason: str = "",
18+
info: str = "",
19+
response: AsyncResponse | Response | None = None,
20+
):
1521
super(BaseException, self).__init__()
1622
self.status_code = status_code
1723
self.reason = reason
@@ -27,25 +33,25 @@ def __str__(self):
2733
class NextcloudExceptionNotModified(NextcloudException):
2834
"""The exception indicates that there is no need to retransmit the requested resources."""
2935

30-
def __init__(self, reason="Not modified", info: str = "", response: Response | None = None):
36+
def __init__(self, reason="Not modified", info: str = "", response: AsyncResponse | Response | None = None):
3137
super().__init__(304, reason=reason, info=info, response=response)
3238

3339

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

37-
def __init__(self, reason="Not found", info: str = "", response: Response | None = None):
43+
def __init__(self, reason="Not found", info: str = "", response: AsyncResponse | Response | None = None):
3844
super().__init__(404, reason=reason, info=info, response=response)
3945

4046

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

44-
def __init__(self, reason="Missing capability", info: str = "", response: Response | None = None):
50+
def __init__(self, reason="Missing capability", info: str = "", response: AsyncResponse | Response | None = None):
4551
super().__init__(412, reason=reason, info=info, response=response)
4652

4753

48-
def check_error(response: Response, info: str = ""):
54+
def check_error(response: AsyncResponse | Response, info: str = ""):
4955
"""Checks HTTP code from Nextcloud, and raises exception in case of error.
5056
5157
For the OCS and DAV `code` be code returned by HTTP and not the status from ``ocs_meta``.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ dynamic = [
4848
dependencies = [
4949
"fastapi>=0.133",
5050
"filelock>=3.20.3,<4",
51-
"niquests>=3,<4",
51+
"niquests>=3.4.2,<4",
5252
"pydantic>=2.1.1",
5353
"python-dotenv>=1",
5454
"starlette>=1.0.1",

0 commit comments

Comments
 (0)