Whenever the error handler now gets an error, and an API was called, we will still output a valid API message unless an exception contains an HTML message. In this case it will just display the HTML message as it is usually supposed to be in a nice format etc. Not sure re any possible side effects. I tested maintenance mode, and some other errors and they were still displayed correctly.
Looks good to me. Not merging directly since I left a comment, but you can merge yourself whenever.