mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2026-02-05 03:35:19 -05:00
feat: Implement centralized error capture and handling with new middleware, services, and API endpoints, and add new admin and statistics API views.
This commit is contained in:
@@ -94,6 +94,85 @@ For every versioned entity, verify:
|
||||
|
||||
---
|
||||
|
||||
## 2. Error Handling MUST Use Capture Utilities
|
||||
|
||||
> [!CAUTION]
|
||||
> **NON-NEGOTIABLE REQUIREMENT**
|
||||
|
||||
All error-prone code on both backend AND frontend MUST use the error capture utilities. Errors should flow to the admin dashboard (`/admin/errors`) for monitoring.
|
||||
|
||||
### Backend Requirements
|
||||
|
||||
Use the utilities from `apps.core.utils`:
|
||||
|
||||
```python
|
||||
from apps.core.utils import capture_errors, error_context, capture_and_log
|
||||
|
||||
# ✅ REQUIRED: Decorator on views and critical functions
|
||||
@capture_errors(source='api', severity='high')
|
||||
def create_park(request, data):
|
||||
return ParkService.create(data)
|
||||
|
||||
# ✅ REQUIRED: Context manager for critical operations
|
||||
with error_context('Processing payment', severity='critical'):
|
||||
process_payment()
|
||||
|
||||
# ✅ ACCEPTABLE: Manual capture when you need the error ID
|
||||
except Exception as e:
|
||||
error_id = capture_and_log(e, 'Operation failed', severity='high')
|
||||
```
|
||||
|
||||
### Frontend Requirements
|
||||
|
||||
Use the composables and utilities:
|
||||
|
||||
```typescript
|
||||
// ✅ REQUIRED: Component-level error boundary
|
||||
const { wrap, error, retry } = useErrorBoundary({ componentName: 'RideCard' })
|
||||
const ride = await wrap(() => api.get('/rides/1'), 'Loading ride')
|
||||
|
||||
// ✅ REQUIRED: tryCatch for async operations
|
||||
const [data, error] = await tryCatch(fetchData(), 'Fetching data')
|
||||
|
||||
// ✅ REQUIRED: Report caught errors
|
||||
const { reportError } = useReportError()
|
||||
try { ... } catch (e) { reportError(e, { action: 'Operation' }) }
|
||||
```
|
||||
|
||||
### What Is FORBIDDEN
|
||||
|
||||
```python
|
||||
# ❌ FORBIDDEN: Silent exception swallowing
|
||||
except Exception:
|
||||
pass # VIOLATION! Error lost forever
|
||||
|
||||
# ❌ FORBIDDEN: Logging without dashboard capture
|
||||
except Exception as e:
|
||||
logger.error(e) # VIOLATION! Not visible in dashboard
|
||||
```
|
||||
|
||||
```typescript
|
||||
// ❌ FORBIDDEN: Silent catch
|
||||
catch (e) { console.error(e) } // VIOLATION! Not in dashboard
|
||||
|
||||
// ❌ FORBIDDEN: Uncaptured async errors
|
||||
await riskyOperation() // VIOLATION! No error handling
|
||||
```
|
||||
|
||||
### Compliance Checklist
|
||||
|
||||
- [ ] All API views decorated with `@capture_errors`
|
||||
- [ ] All critical service methods use `error_context`
|
||||
- [ ] All frontend async operations use `tryCatch` or `useErrorBoundary`
|
||||
- [ ] No silent exception swallowing (`except: pass`)
|
||||
- [ ] All caught exceptions reported via utilities
|
||||
|
||||
### Documentation
|
||||
|
||||
Full usage guide: [docs/ERROR_HANDLING.md](file:///Volumes/macminissd/Projects/thrillwiki_django_no_react/docs/ERROR_HANDLING.md)
|
||||
|
||||
---
|
||||
|
||||
## Document Authority
|
||||
|
||||
This document has the same authority as all other `source_docs/` files. Per the `/comply` workflow, these specifications are **immutable law** and must be enforced immediately upon detection of any violation.
|
||||
|
||||
Reference in New Issue
Block a user