Skip to content

[13.x] Serve exception pages as Markdown via Accept header#59371

Open
WendellAdriel wants to merge 1 commit into13.xfrom
feat/error-markdown
Open

[13.x] Serve exception pages as Markdown via Accept header#59371
WendellAdriel wants to merge 1 commit into13.xfrom
feat/error-markdown

Conversation

@WendellAdriel
Copy link
Member

Summary

  • When a client sends Accept: text/markdown, the exception handler returns the same rich markdown payload used by the error page's copy button (text/markdown; charset=UTF-8)
  • Precedence follows the existing pattern: JSON → Markdown → HTML, using a new shouldReturnMarkdown() / shouldRenderMarkdownWhen() API that mirrors the JSON equivalent
  • Debug-off and custom ExceptionRenderer scenarios fall back to a minimal # Server Error document to avoid leaking internals

Changes

  • Renderer: Extracted resolveException() and added renderMarkdown() so HTML and markdown responses share one code path
  • Handler: Added shouldReturnMarkdown, shouldRenderMarkdownWhen, prepareMarkdownResponse, renderExceptionAsMarkdown; updated renderExceptionResponse to branch markdown after JSON
  • RendererTest: 7 new integration tests covering happy path, charset parameter, all precedence combos, debug-off, and custom renderer fallback

Test plan

  • Happy path: Accept: text/markdown returns 500 with markdown content type and rich stack trace
  • Charset parameter: text/markdown; charset=utf-8 works identically
  • JSON > markdown: Accept: application/json, text/markdown returns JSON
  • Markdown > JSON: Accept: text/markdown, application/json returns markdown
  • HTML > markdown: Accept: text/html, text/markdown returns HTML
  • Debug off: no stack trace or message leakage, returns generic "Server Error"
  • Custom ExceptionRenderer: falls back to minimal markdown

When a client sends `Accept: text/markdown`, the exception handler now
returns the same rich markdown payload used by the error page copy
button. Precedence follows the existing pattern: JSON > Markdown > HTML.

Debug-off and custom ExceptionRenderer scenarios fall back to a minimal
`# Server Error` document to avoid leaking internals.
@WendellAdriel WendellAdriel changed the title Serve exception pages as Markdown via Accept header [13.x] Serve exception pages as Markdown via Accept header Mar 25, 2026
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.

1 participant