I’ve just migrated a Node.js site (built on Express) to Heroku, and I’m seeing that in the case of application errors, Heroku shows its custom error page instead of whatever my app is returning.
I’d like it to not do that, since Express already provides a mechanism to do that, and my app does that. Is it possible to tell Heroku to use whatever my app is returning?
One example why I’d prefer this is because my app’s error page can properly show the logged-in or logged-out state, which a static page, e.g. on S3, couldn’t do. Another example is that my app actually shows different pages based on the precise 5xx status code, whereas Heroku treats all 5xx codes the same.
Edit: Thought of another particularly noteworthy example: our app creates unique IDs for every error instance, and shows that ID to the user on the error page, so that if/when they contact us, we can look up that exact error instance in our logs. Wouldn’t be able to do that with a static page.
I realize Heroku only detects errors via the status code, so I could just send 200 back in the case of errors. But that seems wrong — e.g. you don’t send 200 back in the case of 404s. (And come to think of it, how would a REST API on Heroku return JSON for 5xx then? Hopefully Heroku’s custom error pages only override HTML responses?)
Thanks in advance!
To directly answer the question – no, you cannot turn off the Heroku error pages…
The errors that Heroku handle are the ones that your application isn’t, so if your application is catching errors and returning a page, then Heroku won’t intervene.
I have many apps, admittedly not Node, that do this.