maatify/exceptions features a deterministic escalation mechanism.
A common pattern in PHP is to wrap exceptions:
try {
$db->connect(); // Throws 503 System Error
} catch (Exception $e) {
// Attempting to wrap in a business rule exception
throw new class("Cannot process request", 0, $e) extends BusinessRuleMaatifyException {};
}This effectively hides the system failure. Monitoring tools see a 422 (Business Rule) instead of a critical 503 (System Failure).
When wrapping an exception using MaatifyException:
- Category Severity Check: The library compares the severity of the new exception against the previous one.
- HTTP Status Check: The library compares the HTTP status codes.
- Result: The final exception adopts the higher severity category and status.
- Category: If
previous_severity > current_severity, the category is escalated. - HTTP Status: Uses
max(current, previous)to ensure the highest error class is preserved (e.g., 500 overrides 400). - Unknown Categories:
severity()returns 0 for unknown categories, treating them as lowest priority.
SYSTEM(90)RATE_LIMIT(80)AUTHENTICATION(70)AUTHORIZATION(60)VALIDATION(50)BUSINESS_RULE(40)CONFLICT(30)NOT_FOUND(20)UNSUPPORTED(10)
- Original:
SystemMaatifyException(Severity 90, Status 503) - Wrapper:
BusinessRuleMaatifyException(Severity 40, Status 422)
Final Outcome:
- Category:
SYSTEM(Escalated from BusinessRule) - Status: 503 (Escalated from 422)
This guarantees that critical errors are never masked.