Repository navigation
Conversation
UpdateTag and DeleteTag returned the raw gorm.ErrRecordNotFound when the tag id did not exist, so the handlers answered 500 Internal server error although a missing tag is a client-visible 404. Map the record-not-found error to errors.NewNotFoundError in both service methods; other storage errors still surface as 500.
Yuaneen
marked this pull request as ready for review
November 30, 2026 09:22
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
PUT /knowledge-bases/{id}/tags/{tag_id}andDELETE /knowledge-bases/{id}/tags/{tag_id}answered500 Internal server errorwhen the tag id did not exist, for example after another admin deleted the tag or from a stale tag list.Both service methods returned the raw
gorm.ErrRecordNotFoundfromrepo.GetByID, so the handlers could not classify the miss. Map that error toerrors.NewNotFoundError("标签不存在")inUpdateTagandDeleteTag; any other storage error still surfaces as500.DELETE /mcp-services/{id}was fixed the same way in #6208.Type of Change
Related Issue
None.
Testing
TestTagMissingRegistrationReturnsNotFound: PUT/DELETE with an unknown tag id return 404 and noInternal server error.TestTagLookupFailureStaysInternalError: after closing the DB, both still return 500 without echoingdatabase is closed.TestTagMissingRegistrationReturnsNotFoundfailed withexpected: 404, actual: 500; both pass after the fix.go test ./internal/handler -run 'TestTag' -count=1-> okgo build ./internal/application/service ./internal/handler-> okgofmt -lon the changed files -> no outputgit diff --check 71c32af...HEAD-> passesThe full root-module
go test ./...is covered by CI (the local environment cannot link the prebuilt DuckDB archives).golangci-lintis not installed in this environment.Codex assisted with the implementation and test preparation; I reviewed the diff and ran the focused checks above.
Checklist
git diff --checkpasses for the branchgolangci-lint(passes in CI in 2m42s)go test ./...(covered by the CI "Format, vet, test, and build" job, 19m11s, pass)