Skip to content

Commit 8dd1c58

Browse files
authored
Merge pull request #241 from corenting/misc_fixes
fix: handle when user is blocked and other fixes
2 parents e62d164 + c5f808e commit 8dd1c58

36 files changed

+392
-370
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
github: corenting
12
custom: ["https://corenting.fr/donate"]

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Version 0.11.1
2+
3+
- Fix error when trying to access the page of a suspended user
4+
- Fix error 500 when trying to access some wrong URLs
5+
16
# Version 0.11.0
27

38
- Update login code to reduce the number of requests blocked by Reddit (not fully fixed though)

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ USER eddrit
1515
# To keep in sync with poetry.lock to speedup CI
1616
RUN /usr/local/bin/pip install --user \
1717
uvloop==0.21.0 \
18-
lxml==5.3.1 \
18+
lxml==5.3.2 \
1919
httptools==0.6.4 \
2020
MarkupSafe==3.0.2 \
2121
pyyaml==6.0.2

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ The following configuration parameters are also available:
7878

7979
## Donations
8080

81-
If you wish to support the app, donations are possible [here](https://corenting.fr/donate).
81+
If you wish to support the app, donations are possible on [Github Sponsors](https://github.com/sponsors/corenting/) or [here](https://corenting.fr/donate).
8282

8383
## Credits
8484

eddrit/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from eddrit import config
66

7-
__version__ = "0.11.0"
7+
__version__ = "0.11.1"
88

99
logger.remove()
1010
logger.add(sys.stderr, level=config.LOG_LEVEL)

eddrit/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ class UserUnavailableError(Exception):
1717
detail = "User is not available"
1818

1919

20+
class UserSuspendedError(RedditContentUnavailableError):
21+
detail = "User suspended"
22+
23+
24+
class UserBlockedError(RedditContentUnavailableError):
25+
detail = "User blocked"
26+
27+
2028
class UserNotFoundError(RedditContentUnavailableError):
2129
detail = "User not found"
2230

eddrit/reddit/fetch.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
ContentCannotBeViewedError,
1212
RateLimitedError,
1313
SubredditNotFoundError,
14+
UserBlockedError,
1415
UserNotFoundError,
16+
UserSuspendedError,
1517
WikiPageNotFoundError,
1618
)
1719
from eddrit.reddit import parser
@@ -289,6 +291,12 @@ async def get_user_information(
289291
raise UserNotFoundError(res.status_code)
290292

291293
json = res.json()
294+
295+
if json.get("data", {}).get("is_suspended", False):
296+
raise UserSuspendedError(res.status_code)
297+
if json.get("data", {}).get("is_blocked", False):
298+
raise UserBlockedError(res.status_code)
299+
292300
return parser.parse_user_information(json)
293301

294302

eddrit/routes/pages/index.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from starlette.exceptions import HTTPException
12
from starlette.requests import Request
23
from starlette.responses import Response
34
from starlette.routing import Route
@@ -25,15 +26,19 @@ def _get_request_context_for_index(
2526
"""
2627
Get common request context for the index page.
2728
"""
28-
# Get sorting mode
29-
sorting_mode = models.SubredditSortingMode(
30-
request.path_params.get("sorting_mode", models.SubredditSortingMode.HOT)
31-
)
32-
33-
# Get sorting period
34-
sorting_period = models.SubredditSortingPeriod(
35-
request.query_params.get("t", models.SubredditSortingPeriod.DAY)
36-
)
29+
try:
30+
# Get sorting mode
31+
sorting_mode = models.SubredditSortingMode(
32+
request.path_params.get("sorting_mode", models.SubredditSortingMode.HOT)
33+
)
34+
35+
# Get sorting period
36+
sorting_period = models.SubredditSortingPeriod(
37+
request.query_params.get("t", models.SubredditSortingPeriod.DAY)
38+
)
39+
# In this case it's probably just a wrong URL on the index, return 404
40+
except Exception:
41+
raise HTTPException(status_code=404)
3742

3843
request_pagination = models.Pagination(
3944
before_post_id=request.query_params.get("before"),

poetry.lock

Lines changed: 323 additions & 323 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/browserconfig.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)