Files
mtusi2026lab2/src/messenger/messaging/entrypoints/errors.py
T
ArtyomandClaude Opus 5.5 34741dc2d2 Refuse failed attachments in messages through a zone port
The messaging zone asks a new AttachmentStates port whether any listed
attachment of the chat has failed and answers 409 conflict before the
message is stored; queued and processing attachments can still be
sent right after the upload. The check runs only on the first execution
of a key, so a replay returns the original 201 even if the attachment
failed later. main.py wires the port to the attachments directory, so
neither zone reads the other's tables.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-29 01:09:31 +03:00

23 lines
726 B
Python

from messenger.messaging.domain.errors import (
AttachmentUnavailable,
ChatNotFound,
IdempotencyConflict,
InvalidAttachmentList,
InvalidChatData,
InvalidMessageText,
InvalidPageRequest,
UnknownAttachment,
)
from messenger.shared.domain.errors import DomainError
ERROR_CODES: dict[type[DomainError], tuple[str, int]] = {
InvalidChatData: ("invalid_request", 400),
InvalidMessageText: ("invalid_request", 400),
InvalidPageRequest: ("invalid_request", 400),
InvalidAttachmentList: ("invalid_request", 400),
ChatNotFound: ("not_found", 404),
UnknownAttachment: ("not_found", 404),
IdempotencyConflict: ("conflict", 409),
AttachmentUnavailable: ("conflict", 409),
}