mirror of
https://github.com/langgenius/dify.git
synced 2026-11-14 07:11:06 +08:00
28 lines
1.1 KiB
Python
28 lines
1.1 KiB
Python
"""Error contracts adapting strict moderation to the existing app-generation boundary.
|
|
|
|
The moderation use case remains transport-neutral. Model adapters raise these
|
|
errors so legacy task handling and HTTP/SSE transports preserve the same public
|
|
classification without importing concrete moderation gateways.
|
|
"""
|
|
|
|
from core.app.apps.exc import AppGenerateError
|
|
from services.moderation_service import ModerationRejectedError
|
|
|
|
|
|
class ModerationRejectedInvocationError(ModerationRejectedError, AppGenerateError):
|
|
"""Preserve a strict rejection while exposing the existing app-generation error contract."""
|
|
|
|
error_code = "moderation_rejected"
|
|
status_code = 400
|
|
|
|
|
|
class ModerationUnavailableInvocationError(AppGenerateError):
|
|
"""Fail closed without exposing provider credentials, plugin errors, or rejected content."""
|
|
|
|
error_code = "moderation_unavailable"
|
|
status_code = 503
|
|
|
|
def __init__(self) -> None:
|
|
"""Expose a safe retry message; the raising adapter retains the private cause."""
|
|
super().__init__("Content moderation is temporarily unavailable. Please try again later.")
|