Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

Refactor: remove redundant full module paths in exception handlers (#23076)

Yongtao Huang57e0a12ccdbf
diff --git a/api/controllers/console/app/message.py b/api/controllers/console/app/message.py
index 5e79e8decea..d4ce5921c26 100644
--- a/api/controllers/console/app/message.py
+++ b/api/controllers/console/app/message.py
@@ -5,7 +5,6 @@ from flask_restful import Resource, fields, marshal_with, reqparse
from flask_restful.inputs import int_range
from werkzeug.exceptions import Forbidden, InternalServerError, NotFound
-import services
from controllers.console import api
from controllers.console.app.error import (
CompletionRequestError,
@@ -133,7 +132,7 @@ class MessageFeedbackApi(Resource):
rating=args.get("rating"),
content=None,
)
- except services.errors.message.MessageNotExistsError:
+ except MessageNotExistsError:
raise NotFound("Message Not Exists.")
return {"result": "success"}
diff --git a/api/controllers/console/explore/message.py b/api/controllers/console/explore/message.py
index 822777604a1..de95a9e7b0e 100644
--- a/api/controllers/console/explore/message.py
+++ b/api/controllers/console/explore/message.py
@@ -5,7 +5,6 @@ from flask_restful import marshal_with, reqparse
from flask_restful.inputs import int_range
from werkzeug.exceptions import InternalServerError, NotFound
-import services
from controllers.console.app.error import (
AppMoreLikeThisDisabledError,
CompletionRequestError,
@@ -29,7 +28,11 @@ from models.model import AppMode
from services.app_generate_service import AppGenerateService
from services.errors.app import MoreLikeThisDisabledError
from services.errors.conversation import ConversationNotExistsError
-from services.errors.message import MessageNotExistsError, SuggestedQuestionsAfterAnswerDisabledError
+from services.errors.message import (
+ FirstMessageNotExistsError,
+ MessageNotExistsError,
+ SuggestedQuestionsAfterAnswerDisabledError,
+)
from services.message_service import MessageService
@@ -52,9 +55,9 @@ class MessageListApi(InstalledAppResource):
return MessageService.pagination_by_first_id(
app_model, current_user, args["conversation_id"], args["first_id"], args["limit"]
)
- except services.errors.conversation.ConversationNotExistsError:
+ except ConversationNotExistsError:
raise NotFound("Conversation Not Exists.")
- except services.errors.message.FirstMessageNotExistsError:
+ except FirstMessageNotExistsError:
raise NotFound("First Message Not Exists.")
@@ -77,7 +80,7 @@ class MessageFeedbackApi(InstalledAppResource):
rating=args.get("rating"),
content=args.get("content"),
)
- except services.errors.message.MessageNotExistsError:
+ except MessageNotExistsError:
raise NotFound("Message Not Exists.")
return {"result": "success"}
diff --git a/api/controllers/service_api/app/message.py b/api/controllers/service_api/app/message.py
index d90fa2081f0..a4f95cb1cbd 100644
--- a/api/controllers/service_api/app/message.py
+++ b/api/controllers/service_api/app/message.py
@@ -15,7 +15,11 @@ from fields.message_fields import agent_thought_fields, feedback_fields
from fields.raws import FilesContainedField
from libs.helper import TimestampField, uuid_value
from models.model import App, AppMode, EndUser
-from services.errors.message import SuggestedQuestionsAfterAnswerDisabledError
+from services.errors.message import (
+ FirstMessageNotExistsError,
+ MessageNotExistsError,
+ SuggestedQuestionsAfterAnswerDisabledError,
+)
from services.message_service import MessageService
@@ -65,7 +69,7 @@ class MessageListApi(Resource):
)
except services.errors.conversation.ConversationNotExistsError:
raise NotFound("Conversation Not Exists.")
- except services.errors.message.FirstMessageNotExistsError:
+ except FirstMessageNotExistsError:
raise NotFound("First Message Not Exists.")
@@ -87,7 +91,7 @@ class MessageFeedbackApi(Resource):
rating=args.get("rating"),
content=args.get("content"),
)
- except services.errors.message.MessageNotExistsError:
+ except MessageNotExistsError:
raise NotFound("Message Not Exists.")
return {"result": "success"}
@@ -117,7 +121,7 @@ class MessageSuggestedApi(Resource):
questions = MessageService.get_suggested_questions_after_answer(
app_model=app_model, user=end_user, message_id=message_id, invoke_from=InvokeFrom.SERVICE_API
)
- except services.errors.message.MessageNotExistsError:
+ except MessageNotExistsError:
raise NotFound("Message Not Exists.")
except SuggestedQuestionsAfterAnswerDisabledError:
raise BadRequest("Suggested Questions Is Disabled.")
diff --git a/api/controllers/web/message.py b/api/controllers/web/message.py
index f2e18736010..7bb81cd0d3e 100644
--- a/api/controllers/web/message.py
+++ b/api/controllers/web/message.py
@@ -4,7 +4,6 @@ from flask_restful import fields, marshal_with, reqparse
from flask_restful.inputs import int_range
from werkzeug.exceptions import InternalServerError, NotFound
-import services
from controllers.web import api
from controllers.web.error import (
AppMoreLikeThisDisabledError,
@@ -29,7 +28,11 @@ from models.model import AppMode
from services.app_generate_service import AppGenerateService
from services.errors.app import MoreLikeThisDisabledError
from services.errors.conversation import ConversationNotExistsError
-from services.errors.message import MessageNotExistsError, SuggestedQuestionsAfterAnswerDisabledError
+from services.errors.message import (
+ FirstMessageNotExistsError,
+ MessageNotExistsError,
+ SuggestedQuestionsAfterAnswerDisabledError,
+)
from services.message_service import MessageService
@@ -73,9 +76,9 @@ class MessageListApi(WebApiResource):
return MessageService.pagination_by_first_id(
app_model, end_user, args["conversation_id"], args["first_id"], args["limit"]
)
- except services.errors.conversation.ConversationNotExistsError:
+ except ConversationNotExistsError:
raise NotFound("Conversation Not Exists.")
- except services.errors.message.FirstMessageNotExistsError:
+ except FirstMessageNotExistsError:
raise NotFound("First Message Not Exists.")
@@ -96,7 +99,7 @@ class MessageFeedbackApi(WebApiResource):
rating=args.get("rating"),
content=args.get("content"),
)
- except services.errors.message.MessageNotExistsError:
+ except MessageNotExistsError:
raise NotFound("Message Not Exists.")
return {"result": "success"}