Appearance
Custom Error Pages Implementation
Overview
This document provides technical documentation for implementing custom error pages using the ErrorsPage module. It describes the components, configuration options, and implementation details for creating and managing custom error pages in your application.
Technical Components
Models
Setting
: Stores error code configurations with associated imagesReport
: Logs error reports with details like status code, message, file, and line
Traits
TenantInteractsWithErrorsPage
php
namespace Modules\ErrorsPage\Traits;
// Trait for tenant models to interact with error pages
trait TenantInteractsWithErrorsPage
{
// Relationship to error page settings
public function settings(): HasMany;
// Relationship to error reports
public function reports(): HasMany;
}
Configuration
The module provides a settings page accessible through the Filament admin panel. The configuration includes:
Error Code Settings
- Error code (e.g., 404, 500)
- Custom image for the error page
- Active status
Implementation
1. Setup
After installing the module, you need to:
- Add the
TenantInteractsWithErrorsPage
trait to your tenant model (typicallyCompany
orTeam
) - Configure error pages through the Filament admin panel
php
use Modules\ErrorsPage\Traits\TenantInteractsWithErrorsPage;
class Company extends Model
{
use TenantInteractsWithErrorsPage;
// Rest of your model
}
2. Creating Custom Error Pages
- Navigate to the ErrorsPage settings in your Filament admin panel
- Create a new error page configuration:
- Enter the HTTP error code (e.g., 404, 500)
- Upload a custom image to display on the error page
- Set the APP_DEBUG environment variable to
false
in your.env
file (this ensures custom error pages are displayed instead of detailed debugging information, which should only be shown in development environments)
💡 Important Tips
Internal Server Errors (500): The module automatically handles all internal application errors (exceptions, fatal errors, etc.) and maps them to error code 500. If you want to provide a custom page for these internal errors, make sure to configure an error page for code 500.
Livewire Integration: This module replaces Livewire's default error modal with your custom error pages, providing a more consistent user experience across your application.
3. Error Handling
The module automatically:
- Intercepts HTTP errors with configured error codes
- Displays the custom error page with the configured image
- Logs error reports for tracking and analysis
Error Reporting
The module includes error reporting functionality that:
- Captures error details (status code, message, file, line)
- Associates errors with the current tenant
- Provides a reporting interface in the admin panel
Best Practices
- Common Error Codes: Configure custom pages for common error codes (404, 500, 403)
- Optimized Images: Use appropriately sized and optimized images for error pages
- Consistent Branding: Maintain consistent branding in your error pages
- Helpful Messages: Include helpful messages and navigation options on error pages
- Regular Monitoring: Regularly review error reports to identify and fix issues