holicz/simple-exception
Lightweight base exception for PHP/Laravel with structured context: a safe public message for users, a private debug message for logs, and an HTTP status code. Create your own exceptions by extending BaseException and pass an ExceptionContext.
Standardized Error Responses for APIs:
Implement consistent JSON error formats across all API endpoints (e.g., { "error": "public_message", "debug": null }), improving client SDKs and documentation. This aligns with roadmap items for API-first development and developer experience (DX).
Debugging Efficiency: Accelerate incident response by centralizing technical error details in logs while shielding users from sensitive data. Supports SRE/DevOps goals for faster MTTR (Mean Time to Resolution).
Build vs. Buy for Core Utilities:
Avoid reinventing exception handling for a low-risk, high-reward feature. The package’s simplicity reduces technical debt compared to custom solutions or framework-specific alternatives (e.g., Symfony’s ErrorHandler).
Use Cases:
Roadmap Alignment:
Adopt if:
public/private message logic).Look elsewhere if:
ErrorHandler or Laravel’s built-in exceptions).vendor/).errors.New) are preferred.*"This package standardizes how our application handles errors, delivering three key benefits:
Investment: Minimal (a few hours to adopt). ROI: Hours saved monthly in debugging + reduced API churn. Risk: Low—if the package stalls, we can fork it in a day. Recommendation: Pilot in our payment module to validate impact before rolling out."*
*"Problem: Our exceptions are a mess—some have user messages, others don’t; debug details leak to logs inconsistently; APIs return mixed error formats.
Solution: This package gives us a single source of truth for exceptions:
user_id, transaction_id) to errors without bloating classes.How We’d Use It:
BaseException (e.g., PaymentFailedException).ExceptionContext.App\Exceptions\Handler to return structured JSON:
return response()->json([
'error' => $e->getPublicMessage(),
'debug' => app()->debug() ? $e->getDebugMessage() : null,
], $e->getStatusCode());
Tradeoffs:
Proposal: Let’s dogfood this in the checkout flow (high-error volume) and measure:
Key Talking Points:
Carbon for dates, but for errors."How can I help you explore Laravel packages today?