Skip to content

Commit

Permalink
fixup! Refactor: Improve prices API code with better HTTP errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hoh committed Jan 18, 2024
1 parent 4616d76 commit d729ff5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/aleph/db/accessors/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from ..models.pending_messages import PendingMessageDb


def get_message_by_item_hash(session: DbSession, item_hash: str) -> Optional[MessageDb]:
def get_message_by_item_hash(session: DbSession, item_hash: ItemHash) -> Optional[MessageDb]:
select_stmt = (
select(MessageDb)
.where(MessageDb.item_hash == item_hash)
Expand Down
8 changes: 4 additions & 4 deletions src/aleph/web/controllers/prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class HTTPProcessing(HTTPException):

# Mapping between message statuses to their corresponding exceptions and messages
MESSAGE_STATUS_EXCEPTIONS = {
MessageStatusDb.statuses.PENDING: (HTTPProcessing, "Message still pending"),
MessageStatusDb.statuses.REJECTED: (web.HTTPNotFound, "This message was rejected"),
MessageStatusDb.statuses.FORGOTTEN: (
MessageStatusDb.status.PENDING: (HTTPProcessing, "Message still pending"),
MessageStatusDb.status.REJECTED: (web.HTTPNotFound, "This message was rejected"),
MessageStatusDb.status.FORGOTTEN: (
web.HTTPGone,
"This message has been forgotten",
),
Expand Down Expand Up @@ -58,7 +58,7 @@ async def get_executable_message(session: DbSession, item_hash_str: str) -> Mess
if message_status_db.status in MESSAGE_STATUS_EXCEPTIONS:
exception, message = MESSAGE_STATUS_EXCEPTIONS[message_status_db.status]
raise exception(body=f"{message}: {item_hash_str}")
assert message_status_db.status == MessageStatusDb.statuses.PROCESSED
assert message_status_db.status == MessageStatusDb.status.PROCESSED

# Get the message from the database
message = get_message_by_item_hash(session, item_hash)
Expand Down

0 comments on commit d729ff5

Please sign in to comment.