Added readable exception if no posts were found for task

This commit is contained in:
Igor Miagkov
2022-12-29 20:09:40 +04:00
committed by Andreas Köpf
parent c5053ed6c9
commit 4ead078f89
2 changed files with 3 additions and 0 deletions
+1
View File
@@ -34,6 +34,7 @@ class OasstErrorCode(IntEnum):
INVALID_TASK_TYPE = 2004
USER_NOT_SPECIFIED = 2005
NO_THREADS_FOUND = 2006
NO_REPLIES_FOUND = 2007
WORK_PACKAGE_NOT_FOUND = 2100
WORK_PACKAGE_EXPIRED = 2101
WORK_PACKAGE_PAYLOAD_TYPE_MISMATCH = 2102
@@ -445,6 +445,8 @@ class PromptRepository:
parent = parent.order_by(func.random()).limit(1).subquery()
replies = self.db.query(Post).filter(Post.parent_id.in_(parent)).order_by(func.random()).limit(max_size).all()
if not replies:
raise OasstError("No replies found", OasstErrorCode.NO_REPLIES_FOUND)
thread = self.fetch_thread(replies[0].thread_id)
thread = {p.id: p for p in thread}