fix(api): map INVALID_FOREIGN_KEY and INVALID_WORKSPACE to 400 - #14964
Open
Adityaj0 wants to merge 1 commit into
Open
fix(api): map INVALID_FOREIGN_KEY and INVALID_WORKSPACE to 400#14964Adityaj0 wants to merge 1 commit into
Adityaj0 wants to merge 1 commit into
Conversation
kong.db.errors defines INVALID_FOREIGN_KEY (raised by the DAO when a unique lookup targets a foreign-typed field with a malformed value, e.g. via a generic :select_by_<field> Admin API lookup) and INVALID_WORKSPACE (raised by the postgres strategy on a ws_id foreign key violation, reachable when a workspace is deleted concurrently with a write to one of its entities). Neither code was present in ERRORS_HTTP_CODES, so both fell through to the generic `if not status or status == 500` branch and were turned into an opaque 500 "An unexpected error occurred", discarding the real, actionable error message that only reached the server logs. Both codes represent a client-fixable, 400-class problem, consistent with the neighboring FOREIGN_KEY_VIOLATION/INVALID_PRIMARY_KEY entries already in this table.
1 task
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.
Summary
Fixes #14963.
kong.db.errorsdefinesINVALID_FOREIGN_KEYandINVALID_WORKSPACE, both of which are actually raised by the DAO layer with safe, actionable, client-facing messages, but neither was present inkong/api/endpoints.lua'sERRORS_HTTP_CODEStable. Both codes therefore fell through to the genericif not status or status == 500branch and were turned into an opaque500 "An unexpected error occurred", discarding the real error message (which only reached the server logs).Changes
kong/api/endpoints.lua: addedINVALID_FOREIGN_KEYandINVALID_WORKSPACEtoERRORS_HTTP_CODES, both mapped to400, consistent with the neighboringFOREIGN_KEY_VIOLATION/INVALID_PRIMARY_KEYentries already in the table for analogous client-side validation problems.I did not touch
TRANSFORMATION_ERROR(also missing from the table) since it represents a server-side/data-at-rest issue analogous to the already-intentionally-500DATABASE_ERROR, rather than a client-triggerable, message-safe case like the two above — happy to discuss if maintainers feel it should be included too.Test plan
handle_erroris a private local function inendpoints.luaand not covered by an existing unit-test seam; exercising the exact HTTP status without a running Admin API integration test wasn't something I could safely author and verify without a local test-execution environment (see below). The change itself is a minimal, 2-line, same-pattern addition to an existing table.luac -psyntax-checked the changed file.