mirror of
https://github.com/langgenius/dify.git
synced 2026-11-24 20:59:04 +08:00
26 lines
1018 B
Python
26 lines
1018 B
Python
"""Flask error responses for trigger endpoints.
|
|
|
|
Request parsing failures retain their HTTP status and response. Route handlers
|
|
translate domain failures; unexpected failures are rendered here after unwinding
|
|
the handler, so they cannot swallow a framework-generated 400 or 413.
|
|
"""
|
|
|
|
import logging
|
|
|
|
from flask import Blueprint, Response, jsonify, request
|
|
from werkzeug.exceptions import HTTPException
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def register_error_handlers(blueprint: Blueprint) -> None:
|
|
@blueprint.errorhandler(HTTPException)
|
|
def handle_http_error(error: HTTPException) -> HTTPException:
|
|
return error
|
|
|
|
@blueprint.errorhandler(Exception)
|
|
def handle_unexpected_error(error: Exception) -> tuple[Response, int]:
|
|
logger.exception("Trigger request failed for %s", request.path)
|
|
message = str(error) if request.endpoint == "trigger.handle_webhook" else "An internal error has occurred."
|
|
return jsonify({"error": "Internal server error", "message": message}), 500
|