Skip to content

Commit

Permalink
Fixes the testing for server errors again
Browse files Browse the repository at this point in the history
  • Loading branch information
stumpylog committed Sep 30, 2024
1 parent 2916818 commit 603bf89
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- All routes now return a stronger typed response than just an `httpx.Response` ([#23](https://github.com/stumpylog/gotenberg-client/pull/23))
- All public methods now include docstrings ([#33](https://github.com/stumpylog/gotenberg-client/pull/33))

### Changed

Expand Down
4 changes: 2 additions & 2 deletions src/gotenberg_client/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ def _base_run_with_retry(

# Don't do the extra waiting, return right away
if current_retry_count >= max_retry_count:
raise MaxRetriesExceededError from e
raise MaxRetriesExceededError(response=e.response) from e

except Exception as e: # pragma: no cover
logger.warning(f"Unexpected error: {e}", stacklevel=1)
if current_retry_count > -max_retry_count:
raise MaxRetriesExceededError from e
raise

sleep(retry_time)
retry_time = retry_time * retry_scale
Expand Down
7 changes: 7 additions & 0 deletions src/gotenberg_client/_errors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from httpx import Response


class BaseClientError(Exception):
"""
Base exception for any errors raised directly by this library
Expand All @@ -13,6 +16,10 @@ class MaxRetriesExceededError(BaseClientError):
Raised if the number of retries exceeded the configured maximum
"""

def __init__(self, *, response: Response) -> None:
super().__init__()
self.response = response


class CannotExtractHereError(BaseClientError):
pass
3 changes: 2 additions & 1 deletion tests/test_misc_stuff.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib import Path

import pytest
from httpx import HTTPStatusError
from httpx import Request
from httpx import codes
from pytest_httpx import HTTPXMock
Expand Down Expand Up @@ -118,7 +119,7 @@ def test_not_a_server_error(self, client: GotenbergClient, httpx_mock: HTTPXMock
test_file = SAMPLE_DIR / "basic.html"

with client.chromium.html_to_pdf() as route:
with pytest.raises(MaxRetriesExceededError) as exc_info:
with pytest.raises(HTTPStatusError) as exc_info:
_ = route.index(test_file).run_with_retry(initial_retry_wait=0.1, retry_scale=0.1)
assert exc_info.value.response.status_code == codes.NOT_FOUND

Expand Down

0 comments on commit 603bf89

Please sign in to comment.