Skip to content

[Bug] Non-existent resource returns code 500 instead of 404 #4813

@time2024

Description

@time2024

Contact Information

zenith30@qq.com

MaxKB Version

v1.10.x (latest Docker image)

Problem Description

When accessing a knowledge base with a valid UUID format but the resource does not exist in the database, the API returns {"code": 500} instead of {"code": 404}. According to HTTP semantics (RFC 7231 Section 6.5.4), a request for a resource that does not exist should return 404 Not Found. This affects GET, PUT, and DELETE operations.

Steps to Reproduce

GET non-existent knowledge base (valid UUID format, but does not exist)

curl -s -H "Authorization: Bearer <your_token>"
http://localhost:8080/admin/api/workspace/default/knowledge/01a5b0e5-5a50-49bc-a3b3-580a78aca870

PUT non-existent knowledge base

curl -s -X PUT
-H "Authorization: Bearer <your_token>"
-H "Content-Type: application/json"
-d '{"name":"test"}'
http://localhost:8080/admin/api/workspace/default/knowledge/01a5b0e5-5a50-49bc-a3b3-580a78aca870

DELETE non-existent knowledge base

curl -s -X DELETE -H "Authorization: Bearer <your_token>"
http://localhost:8080/admin/api/workspace/default/knowledge/01a5b0e5-5a50-49bc-a3b3-580a78aca870

The expected correct result

{"code": 404, "message": "Knowledge id does not exist", "data": null}

Related log output

All three methods return:
{"code": 500, "message": "Knowledge id does not exist", "data": null}

Additional Information

15+ test cases with random valid UUIDs all reproduce this. The error message already correctly identifies the problem ("does not exist"), but the error code should be 404, not 500.

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