IIS 8.5 overriding custom JSON error response, instead returns the default 500 error response page. How can I get IIS 8.5 to return my custom error?

I’ve come across an annoying issue, which I think is being caused by IIS 8.5. With a web app that I’m creating, I have created a custom JSON HttpStatusResult class (which was an idea from this stackoverflow post), which enables me to return JSON along side a 500, 400 or other types of HTTP response status codes. Here is that code: