When there is an uncaught exception, Drupal 8 displays a simple dump of the exception.

I find that the page is served as 'Content-Type' = 'text/plain', yet it contains HTML: Error as plain text

It looks better to me when I change the code to serve as 'text/html': Error as HTML

I already found the code to change - it's in FinalExceptionSubscriber.php, which outputs

Formats a string for HTML display by replacing variable placeholders.

My question is:

  1. Does anyone know a reason why the error page is text/plain given that it contains HTML.
  2. Shall I raise an issue and patch?
  • 1
    Because this is the most generic exception subscriber for exceptions not handled by any format specific exception subscriber (like html or json).
    – 4uk4
    Nov 5, 2017 at 16:52
  • @4k4 Thanks for explaining. However it seems that the exceptions do contain HTML. The <br><br> is always there and SafeMarkup::format description is "Formats a string for HTML display by replacing variable placeholders"
    – AdamS
    Nov 6, 2017 at 17:43
  • (Question edited to clarify that the output does contain HTML)
    – AdamS
    Nov 6, 2017 at 17:49
  • Yes, that's a bit inconsistent. But you would never show this message in production. If you want to react to a custom exception you would do this in your own exception subscriber.
    – 4uk4
    Nov 6, 2017 at 17:52
  • 1
    This would revert this issue Standardize fatal error/exception handling: backtrace for all formats, not just HTML. Better follow up on this issue and improve the text formatting.
    – 4uk4
    Nov 7, 2017 at 8:11

1 Answer 1


Thanks @4k4, so it seems that this is a minor bug, but the obvious fix would revert the "Standardize handling" issue.

I have raised this issue and linked it to the other issue. I don't really understand the code here and would welcome any help to improve the issue text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.