404 and 500 Pages

Adds custom 404 and 500 error pages to your Phoenix application with proper templates and error handling. Replaces Phoenix's default error pages with branded, user-friendly versions that maintain consistency with your application's design.

Key Benefits

  • Professional error handling - Custom-designed error pages that match your application's branding
  • Developer-friendly fallback module - Dedicated exception handling for LiveView route errors
  • Test-ready implementation - Automatically updates test assertions to work with custom templates
  • Production-ready styling - Responsive error pages with proper meta tags and CSRF protection

Implementation Details The feature installs custom HTML templates for 404 and 500 errors, enabling the embed_templates functionality in your ErrorHTML controller. It creates a dedicated Fallback exception module for LiveView error handling and updates existing tests to use regex matching instead of exact string comparison for more flexible error page testing.

Usage Example

# In a LiveView when a resource is not found
defmodule MyAppWeb.PostLive do
  def mount(%{"id" => id}, _session, socket) do
    case Posts.get_post(id) do
      nil -> raise MyAppWeb.Fallback
      post -> {:ok, assign(socket, :post, post)}
    end
  end
end

Configuration No additional configuration required. The feature automatically generates responsive error templates with proper internationalization support using gettext/1 and maintains your existing Phoenix pipeline structure.