Skip to content

[Bug] Invalid UUID path parameter returns code 500 instead of 400 #4812

@time2024

Description

@time2024

Contact Information

zenith30@qq.com

MaxKB Version

v1.10.x (latest Docker image)

Problem Description

When a non-UUID value is passed as a resource ID in URL path parameters (knowledge base ID or document ID), the API returns {"code": 500} instead of {"code": 400}. Input validation errors should return 400 Bad Request, not 500 Internal Server Error. This affects both /knowledge/{id} and /knowledge/{id}/document/{doc_id} endpoints.

Steps to Reproduce

Test 1: Non-UUID knowledge base ID

curl -s -H "Authorization: Bearer <your_token>"
http://localhost:8080/admin/api/workspace/default/knowledge/not-a-uuid

Test 2: Numeric document ID

curl -s -H "Authorization: Bearer <your_token>"
http://localhost:8080/admin/api/workspace/default/knowledge/<your_kb_id>/document/30

Test 3: Other invalid values ("null", "undefined", "NaN", "-1", "0") all trigger the same 500

curl -s -H "Authorization: Bearer <your_token>"
http://localhost:8080/admin/api/workspace/default/knowledge/null

The expected correct result

{"code": 400, "message": "知识库 ID:Must be a valid UUID.", "data": null}

Related log output

Knowledge base ID response:
{"code": 500, "message": "知识库 ID:Must be a valid UUID.", "data": null}
Document ID response:
{"code": 500, "message": "文档 ID:Must be a valid UUID.", "data": null}

Additional Information

25+ different invalid inputs reproduce this consistently. Suggest adding UUID format validation before reaching business logic and returning 400 Bad Request for invalid UUID formats.

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