Fix duplicate-key DB error handling to support all drivers (not only SQLite)
@senthuran16 is already working on this.
Since May 20, 2026.
- Dominant language
- Go
- Stars
- 71
- Forks
- 111
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 110
Description
Summary
Duplicate-key errors from the repository layer are currently only detected for SQLite via isSQLiteUniqueConstraint. When running against other supported databases (e.g. PostgreSQL), a duplicate create operation surfaces as a generic failure instead of mapping to the appropriate sentinel error (e.g. ErrWebBrokerAPIExists, ErrWebSubAPIExists, etc.).
A cross-driver helper (e.g. isDuplicateKeyError) should be introduced that covers driver-specific error codes/messages (PostgreSQL code 23505, MySQL errno 1062, SQLite unique constraint, etc.) and used at all affected call sites.
Affected files
platform-api/src/internal/service/webbroker_api.go(line 154)platform-api/src/internal/service/websub_api.go(line 153)platform-api/src/internal/service/mcp.go(line 136)platform-api/src/internal/service/llm.go(lines 148, 352, 643)
Note: gateway/gateway-controller/pkg/storage/factory.go already uses an abstracted isUniqueViolation function-field pattern, which can serve as a reference for the fix.
References
- Identified during review of PR #1992 (comment: https://github.com/wso2/api-platform/pull/1992#discussion_r3273481565)
- Requested by @senthuran16
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.