docs: add error handling and error pages section to shop architecture
Added comprehensive documentation for: - Error page templates (10 templates) - Error renderer base_url calculation - Multi-access aware error links - Template usage examples (bad vs good) - How error pages work across domain/subdomain/path access This documents the error page improvements made during shop API migration. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -998,6 +998,78 @@ Before Deploying:
|
||||
□ Test in production mode
|
||||
|
||||
|
||||
🚨 ERROR HANDLING & ERROR PAGES
|
||||
═════════════════════════════════════════════════════════════════
|
||||
|
||||
Multi-Access Aware Error Pages:
|
||||
|
||||
All shop error pages (404, 500, etc.) are vendor-context aware and display
|
||||
correct links based on the access method (domain, subdomain, or path-based).
|
||||
|
||||
Error Page Templates:
|
||||
• app/templates/shop/errors/404.html - Not Found
|
||||
• app/templates/shop/errors/400.html - Bad Request
|
||||
• app/templates/shop/errors/401.html - Unauthorized
|
||||
• app/templates/shop/errors/403.html - Forbidden
|
||||
• app/templates/shop/errors/422.html - Validation Error
|
||||
• app/templates/shop/errors/429.html - Rate Limited
|
||||
• app/templates/shop/errors/500.html - Server Error
|
||||
• app/templates/shop/errors/502.html - Bad Gateway
|
||||
• app/templates/shop/errors/base.html - Base error template
|
||||
• app/templates/shop/errors/generic.html - Generic error
|
||||
|
||||
Error Renderer (app/exceptions/error_renderer.py):
|
||||
|
||||
Calculates base_url dynamically based on vendor access method:
|
||||
|
||||
def _get_context_data(self, request: Request, ...):
|
||||
vendor = getattr(request.state, 'vendor', None)
|
||||
access_method = getattr(request.state, "access_method", None)
|
||||
vendor_context = getattr(request.state, "vendor_context", None)
|
||||
|
||||
# Calculate base_url for shop links
|
||||
base_url = "/"
|
||||
if access_method == "path" and vendor:
|
||||
full_prefix = vendor_context.get('full_prefix', '/vendor/')
|
||||
base_url = f"{full_prefix}{vendor.subdomain}/"
|
||||
|
||||
return {
|
||||
"request": request,
|
||||
"vendor": vendor,
|
||||
"base_url": base_url, # ⭐ Used in error templates
|
||||
...
|
||||
}
|
||||
|
||||
Error Template Usage:
|
||||
|
||||
All error page links use {{ base_url }} prefix for correct routing:
|
||||
|
||||
{# ❌ BAD - Hardcoded links #}
|
||||
<a href="/">Continue Shopping</a>
|
||||
<a href="/products">View Products</a>
|
||||
|
||||
{# ✅ GOOD - Context-aware links #}
|
||||
<a href="{{ base_url or '/' }}">Continue Shopping</a>
|
||||
<a href="{{ base_url or '/' }}products">View Products</a>
|
||||
|
||||
How It Works:
|
||||
|
||||
1. Error occurs (404, 500, etc.)
|
||||
2. Exception handler detects shop context
|
||||
3. error_renderer.py calculates base_url from vendor_context
|
||||
4. Error template renders with correct base_url
|
||||
5. Links work for all access methods:
|
||||
- Domain: customshop.com → base_url = "/"
|
||||
- Subdomain: wizamart.platform.com → base_url = "/"
|
||||
- Path: localhost/vendors/wizamart/ → base_url = "/vendors/wizamart/"
|
||||
|
||||
Benefits:
|
||||
✅ Error pages work correctly regardless of access method
|
||||
✅ No broken links in error states
|
||||
✅ Consistent user experience
|
||||
✅ Vendor branding maintained in errors
|
||||
|
||||
|
||||
🔒 SECURITY
|
||||
═════════════════════════════════════════════════════════════════
|
||||
|
||||
|
||||
Reference in New Issue
Block a user