mirror of
https://github.com/langgenius/dify.git
synced 2026-06-17 06:21:07 +08:00
refactor(openapi): own FilenameNotExists error instead of touching the shared class
controllers/common/errors.py is consumed by other controllers; keep it untouched and declare the openapi-surface error as an OpenApiError subclass. Wire output is identical.
This commit is contained in:
parent
57fb121f8a
commit
67229339cb
@ -4,7 +4,6 @@ from libs.exception import BaseHTTPException
|
||||
|
||||
|
||||
class FilenameNotExistsError(HTTPException):
|
||||
error_code = "filename_not_exists"
|
||||
code = 400
|
||||
description = "The specified filename does not exist."
|
||||
|
||||
|
||||
@ -221,6 +221,12 @@ class OpenApiErrorFormatter:
|
||||
return isinstance(part, (str, int)) and not isinstance(part, bool)
|
||||
|
||||
|
||||
class FilenameNotExists(OpenApiError): # noqa: N818
|
||||
code = 400
|
||||
error_code = OpenApiErrorCode.FILENAME_NOT_EXISTS
|
||||
description = "The specified filename does not exist."
|
||||
|
||||
|
||||
class MemberLimitExceeded(OpenApiError): # noqa: N818
|
||||
code = 403
|
||||
error_code = OpenApiErrorCode.MEMBER_LIMIT_EXCEEDED
|
||||
|
||||
@ -10,7 +10,6 @@ from werkzeug.exceptions import BadRequest
|
||||
import services
|
||||
from controllers.common.errors import (
|
||||
BlockedFileExtensionError,
|
||||
FilenameNotExistsError,
|
||||
FileTooLargeError,
|
||||
NoFileUploadedError,
|
||||
TooManyFilesError,
|
||||
@ -18,6 +17,7 @@ from controllers.common.errors import (
|
||||
)
|
||||
from controllers.openapi import openapi_ns
|
||||
from controllers.openapi._contract import returns
|
||||
from controllers.openapi._errors import FilenameNotExists
|
||||
from controllers.openapi.auth.composition import auth_router
|
||||
from controllers.openapi.auth.data import AuthData
|
||||
from extensions.ext_database import db
|
||||
@ -52,7 +52,7 @@ class AppFileUploadApi(Resource):
|
||||
if not file.mimetype:
|
||||
raise UnsupportedFileTypeError()
|
||||
if not file.filename:
|
||||
raise FilenameNotExistsError()
|
||||
raise FilenameNotExists()
|
||||
|
||||
try:
|
||||
upload_file = FileService(db.engine).upload_file(
|
||||
|
||||
@ -16,7 +16,6 @@ from werkzeug.exceptions import (
|
||||
|
||||
from controllers.common.errors import (
|
||||
BlockedFileExtensionError,
|
||||
FilenameNotExistsError,
|
||||
FileTooLargeError,
|
||||
NoFileUploadedError,
|
||||
TooManyFilesError,
|
||||
@ -25,6 +24,7 @@ from controllers.common.errors import (
|
||||
from controllers.openapi._errors import (
|
||||
ErrorBody,
|
||||
ErrorDetail,
|
||||
FilenameNotExists,
|
||||
MemberLicenseExceeded,
|
||||
MemberLimitExceeded,
|
||||
OpenApiError,
|
||||
@ -316,7 +316,7 @@ ERROR_MATRIX = [
|
||||
(UnsupportedFileTypeError(), 415, "unsupported_file_type"),
|
||||
(NoFileUploadedError(), 400, "no_file_uploaded"),
|
||||
(TooManyFilesError(), 400, "too_many_files"),
|
||||
(FilenameNotExistsError(), 400, "filename_not_exists"),
|
||||
(FilenameNotExists(), 400, "filename_not_exists"),
|
||||
(BlockedFileExtensionError(), 400, "file_extension_blocked"),
|
||||
(MemberLimitExceeded(), 403, "member_limit_exceeded"),
|
||||
(MemberLicenseExceeded(), 403, "member_license_exceeded"),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user