From 1f2ccb4668f21f0ca682b64818011930100adf94 Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Tue, 25 Nov 2025 21:06:16 +0100 Subject: [PATCH] refactor: move fallback error templates to shared directory with improved naming MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reorganize error template structure to consolidate shared templates in a dedicated location. Changes: - Move templates/fallback/* to templates/shared/ with -fallback suffix - 404.html β†’ 404-fallback.html - 500.html β†’ 500-fallback.html - generic.html β†’ generic-fallback.html - Update error_renderer.py to use new template paths - Modified template selection logic in _find_template() - Updated documentation strings to reflect new paths - Update error rendering documentation - HTML_ERROR_RENDERING_FLOW_DIAGRAM.md: Updated diagrams and examples - ERROR_RENDERING_DEVELOPER_DOCUMENTATION.md: Updated file structure and paths Benefits: - Clearer organization with all shared templates in shared/ directory - Consistent naming convention (-fallback suffix) indicates purpose - Aligns with existing cdn-fallback.html in same directory πŸ€– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/exceptions/error_renderer.py | 16 ++++++++-------- .../404.html => shared/404-fallback.html} | 0 .../500.html => shared/500-fallback.html} | 0 .../generic-fallback.html} | 0 .../ERROR_RENDERING_DEVELOPER_DOCUMENTATION.md | 15 ++++++++------- .../HTML_ERROR_RENDERING_FLOW_DIAGRAM.md | 16 ++++++++-------- 6 files changed, 24 insertions(+), 23 deletions(-) rename app/templates/{fallback/404.html => shared/404-fallback.html} (100%) rename app/templates/{fallback/500.html => shared/500-fallback.html} (100%) rename app/templates/{fallback/generic.html => shared/generic-fallback.html} (100%) diff --git a/app/exceptions/error_renderer.py b/app/exceptions/error_renderer.py index 40508cab..0642121b 100644 --- a/app/exceptions/error_renderer.py +++ b/app/exceptions/error_renderer.py @@ -69,8 +69,8 @@ class ErrorPageRenderer: Template Selection Priority: 1. Context-specific error page: {context}/errors/{status_code}.html 2. Context-specific generic: {context}/errors/generic.html - 3. Fallback error page: fallback/{status_code}.html - 4. Fallback generic: fallback/generic.html + 3. Shared fallback error page: shared/{status_code}-fallback.html + 4. Shared fallback generic: shared/generic-fallback.html Args: request: FastAPI request object @@ -150,8 +150,8 @@ class ErrorPageRenderer: Priority: 1. {context}/errors/{status_code}.html 2. {context}/errors/generic.html - 3. fallback/{status_code}.html - 4. fallback/generic.html + 3. shared/{status_code}-fallback.html + 4. shared/generic-fallback.html """ templates_dir = ErrorPageRenderer.get_templates_dir() @@ -176,13 +176,13 @@ class ErrorPageRenderer: if (templates_dir / generic_template).exists(): return generic_template - # Try fallback status code template - fallback_specific = f"fallback/{status_code}.html" + # Try shared fallback status code template + fallback_specific = f"shared/{status_code}-fallback.html" if (templates_dir / fallback_specific).exists(): return fallback_specific - # Use fallback generic template (must exist) - return "fallback/generic.html" + # Use shared fallback generic template (must exist) + return "shared/generic-fallback.html" @staticmethod def _prepare_template_data( diff --git a/app/templates/fallback/404.html b/app/templates/shared/404-fallback.html similarity index 100% rename from app/templates/fallback/404.html rename to app/templates/shared/404-fallback.html diff --git a/app/templates/fallback/500.html b/app/templates/shared/500-fallback.html similarity index 100% rename from app/templates/fallback/500.html rename to app/templates/shared/500-fallback.html diff --git a/app/templates/fallback/generic.html b/app/templates/shared/generic-fallback.html similarity index 100% rename from app/templates/fallback/generic.html rename to app/templates/shared/generic-fallback.html diff --git a/docs/development/error-rendering/ERROR_RENDERING_DEVELOPER_DOCUMENTATION.md b/docs/development/error-rendering/ERROR_RENDERING_DEVELOPER_DOCUMENTATION.md index 27290d57..28557d6f 100644 --- a/docs/development/error-rendering/ERROR_RENDERING_DEVELOPER_DOCUMENTATION.md +++ b/docs/development/error-rendering/ERROR_RENDERING_DEVELOPER_DOCUMENTATION.md @@ -85,7 +85,7 @@ app/templates/ β”œβ”€β”€ admin/errors/ # Admin error pages (Phase 1 - COMPLETE) β”œβ”€β”€ vendor/errors/ # Vendor error pages (Phase 2 - PENDING) β”œβ”€β”€ shop/errors/ # Shop error pages (Phase 3 - PENDING) -└── fallback/ # Generic fallback pages (COMPLETE) +└── shared/ # Shared fallback error pages (COMPLETE) ``` --- @@ -153,8 +153,8 @@ ErrorPageRenderer.render_error_page( 1. `{context}/errors/{status_code}.html` (e.g., `admin/errors/404.html`) 2. `{context}/errors/generic.html` (e.g., `admin/errors/generic.html`) -3. `fallback/{status_code}.html` (e.g., `fallback/404.html`) -4. `fallback/generic.html` (absolute fallback) +3. `shared/{status_code}-fallback.html` (e.g., `shared/404-fallback.html`) +4. `shared/generic-fallback.html` (absolute fallback) **Template Variables Provided:** @@ -353,10 +353,11 @@ app/templates/ β”‚ └── errors/ β”‚ └── (same structure as admin) β”‚ -└── fallback/ - β”œβ”€β”€ 404.html - β”œβ”€β”€ 500.html - └── generic.html +└── shared/ + β”œβ”€β”€ 404-fallback.html + β”œβ”€β”€ 500-fallback.html + β”œβ”€β”€ generic-fallback.html + └── cdn-fallback.html ``` ### Base Template Pattern diff --git a/docs/development/error-rendering/HTML_ERROR_RENDERING_FLOW_DIAGRAM.md b/docs/development/error-rendering/HTML_ERROR_RENDERING_FLOW_DIAGRAM.md index 2813956b..58bde264 100644 --- a/docs/development/error-rendering/HTML_ERROR_RENDERING_FLOW_DIAGRAM.md +++ b/docs/development/error-rendering/HTML_ERROR_RENDERING_FLOW_DIAGRAM.md @@ -83,8 +83,8 @@ β”‚ Priority: β”‚ β”‚ 1. {context}/errors/{code} β”‚ β”‚ 2. {context}/errors/genericβ”‚ - β”‚ 3. fallback/{code}.html β”‚ - β”‚ 4. fallback/generic.html β”‚ + β”‚ 3. shared/{code}-fallback β”‚ + β”‚ 4. shared/generic-fallback β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” @@ -152,8 +152,8 @@ For a 404 error in ADMIN context: ``` 1. Check: app/templates/admin/errors/404.html βœ“ EXISTS β†’ USE THIS 2. Check: app/templates/admin/errors/generic.html (skipped) -3. Check: app/templates/fallback/404.html (skipped) -4. Check: app/templates/fallback/generic.html (skipped) +3. Check: app/templates/shared/404-fallback.html (skipped) +4. Check: app/templates/shared/generic-fallback.html (skipped) ``` For a 429 error in SHOP context (not created yet): @@ -161,8 +161,8 @@ For a 429 error in SHOP context (not created yet): ``` 1. Check: app/templates/shop/errors/429.html βœ— Missing 2. Check: app/templates/shop/errors/generic.html βœ— Missing -3. Check: app/templates/fallback/429.html βœ— Missing -4. Check: app/templates/fallback/generic.html βœ“ EXISTS β†’ USE THIS +3. Check: app/templates/shared/429-fallback.html βœ— Missing +4. Check: app/templates/shared/generic-fallback.html βœ“ EXISTS β†’ USE THIS ``` --- @@ -283,8 +283,8 @@ app/ β”‚ β”œβ”€β”€ shop/ β”‚ β”‚ └── errors/ # TODO: Shop error pages (themed) β”‚ β”‚ -β”‚ └── fallback/ -β”‚ └── (minimal pages) # NEW: Unknown context fallback +β”‚ └── shared/ +β”‚ └── *-fallback.html # Shared fallback error pages middleware/ β”œβ”€β”€ vendor_context.py # Vendor detection (existing)