Tenancy-aware custom error page

I found How can I add a custom header to my error pages?, which showed me Plug.ErrorHandler — Plug v1.18.1.

The general advice is to keep error pages simple, independent of existing layouts, minimal dependencies, to avoid more errors when rendering the error page itself.

How do you approach custom error pages when each application tenant has their own branding? E.g. custom name, logo, color scheme.

My expectation would be to have a 404 page better-aligned with the current tenancy than, say, a 500 caused by a DB error.

Anyone aware of open-source Phoenix apps that fit that category as a source of inspiration?

I’d explicitly handle all the error pages you expect to have custom branding on. Leave ErrorHandler to the truely exceptional case.

2 Likes

One approach is to have a plug that “loads” the tenant and sets the path to tenant-specific styling (e.g. CSS, values for tennnt name, etc.) This is pretty common in multi-tenant applications.

Then use ErrorView[1] to implement custom error pages which use those values to customize the error pages.

That way there is no additional loading of data, DB checks, etc in the error template.

To avoid a strange loop between “can’t find that tenant” and an error page that relies on a tenant being found, I tend to use a redirect to a known generic landing page specifically for that case in the “load the tenant” plug.

[1] If using Phoenix; replace with the equivalent handler in whatever framework you are using.

3 Likes

Thanks for the replies!