8000 feat: default error responses to JSON instead of plain text by alexferl · Pull Request #169 · alexferl/zerohttp · GitHub
[go: up one dir, main page]

Skip to content

feat: default error responses to JSON instead of plain text - #169

Merged
alexferl merged 1 commit into
masterfrom
errors
Apr 7, 2026
Merged

alexferl merged 1 commit into
masterfrom
errors

Conversation

@alexferl
@alexferl alexferl commented Apr 7, 2026
Copy link
Copy Markdown
Owner

Change the default behavior when no Accept header is present to return application/problem+json instead of text/plain. This affects:

  • All middleware error responses (circuitbreaker, cors, csrf, host, idempotency, jwtauth, ratelimit, recover, timeout)
  • Router default 404 Not Found and 405 Method Not Allowed handlers

The AcceptsJSON() function now returns true when the Accept header is empty, making JSON the default response format. Clients can still request plain text by sending Accept: text/plain.

Updated all tests to reflect the new default behavior and added explicit tests for plain text responses when requested.

Change the default behavior when no Accept header is present to return
application/problem+json instead of text/plain. This affects:

- All middleware error responses (circuitbreaker, cors, csrf, host,
  idempotency, jwtauth, ratelimit, recover, timeout)
- Router default 404 Not Found and 405 Method Not Allowed handlers

The AcceptsJSON() function now returns true when the Accept header is
empty, making JSON the default response format. Clients can still
request plain text by sending Accept: text/plain.

Updated all tests to reflect the new default behavior and added
explicit tests for plain text responses when requested.

Signed-off-by: alexferl <me@alexferl.com>
@coveralls
Copy link
Copy Markdown

Coverage Report for CI Build 24062537653

Coverage decreased (-0.04%) to 93.915%

Details

  • Coverage decreased (-0.04%) from the base build.
  • Patch coverage: 32 of 32 lines across 3 files are fully covered (100%).
  • 8 coverage regressions across 3 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

8 previously-covered lines in 3 files lost coverage.

File Lines Losing Coverage Coverage
server_tls.go 5 88.24%
validator/registry.go 2 97.26%
server.go 1 89.36%

Coverage Stats

Coverage Status
Relevant Lines: 11273
Covered Lines: 10587
Line Coverage: 93.91%
Coverage Strength: 385.75 hits per line

💛 - Coveralls

@alexferl
alexferl merged commit 23c16dd into master Apr 7, 2026
9 checks passed
@alexferl
alexferl deleted the errors branch April 7, 2026 03:19
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.

2 participants

0