Skip to content

[Bug] File upload with missing required field returns code 500 instead of 400 #4814

@time2024

Description

@time2024

Contact Information

zenith30@qq.com

MaxKB Version

v1.10.x (latest Docker image)

Problem Description

When uploading a file to the knowledge base document endpoint without all required fields (e.g., missing the document type field), the API returns {"code": 500} with message 文档类型:该字段必须填写 instead of a proper 400 Bad Request. Missing required fields are a client-side input error and should return a 4xx status code, not 5xx.

Steps to Reproduce

Upload a file without specifying the required "type" field

curl -s -X POST
-H "Authorization: Bearer <your_token>"
-F "file=@test.pdf"
http://localhost:8080/admin/api/workspace/default/knowledge/<your_kb_id>/document

The expected correct result

{"code": 400, "message": "文档类型:该字段必须填写", "data": null}

Related log output

{"code": 500, "message": "文档类型:该字段必须填写", "data": null}

Additional Information

Tested with 32 different file types (PDF, DOCX, XLSX, MD, TXT, HTML - including empty files, corrupted files, oversized files), all return the same code 500 response. Suggest validating required fields before processing the upload and returning 400 Bad Request.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions