Skip to content

fix: return JSON response for unmatched routes instead of plain text#2457

Merged
cemalkilic merged 5 commits intomasterfrom
cemal/fix-404-as-json-response
Apr 2, 2026
Merged

fix: return JSON response for unmatched routes instead of plain text#2457
cemalkilic merged 5 commits intomasterfrom
cemal/fix-404-as-json-response

Conversation

@cemalkilic
Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Fix

Summary

Routes behind feature flags (e.g. OAuthServer, CustomOAuth) return chi's default plain text "404 page not found" when disabled. Register custom NotFound and MethodNotAllowed handlers on the router so all unmatched routes return structured JSON errors consistent with the rest of the API.

Fixes inconsistent content-type: text/plain responses when feature-gated routes (OAuthServer, CustomOAuth) are disabled

Test plan

  • Hit a disabled route (e.g. /oauth/clients/register with OAuthServer.Enabled=false) and verify JSON 404 response with error_code: "route_not_found"

@cemalkilic cemalkilic requested a review from a team as a code owner March 30, 2026 15:20
Copy link
Copy Markdown
Contributor

@fadymak fadymak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ✅ Might be worth codifying this with a small test

Comment thread internal/api/middleware_test.go
@cemalkilic cemalkilic merged commit 7337e21 into master Apr 2, 2026
4 checks passed
@cemalkilic cemalkilic deleted the cemal/fix-404-as-json-response branch April 2, 2026 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants