dosfarma/exceptions
Lightweight Laravel/PHP exception utilities for standardizing, wrapping, and handling application errors. Helps you define consistent exception types and messages across your codebase, improving error clarity, debugging, and maintainability with minimal setup.
App\Exceptions\Handler) and integrates seamlessly with its middleware pipeline. Minimal architectural disruption expected.spatie/laravel-activitylog for audit trails).request_id or user_context)?Symfony\Component\HttpKernel\Exception\HttpException) that conflict?ValidationException) and "system" errors (e.g., DatabaseException)?App\Exceptions\Handler to use the package’s exception formatter.use Dosfarma\Exceptions\ExceptionFormatter;
public function render($request, Throwable $exception) {
return (new ExceptionFormatter)->render($request, $exception);
}
Route::apiResource() or apiMiddleware groups where consistency is critical.composer require dosfarma/exceptions).auth:api).assertEquals(404, $response->status())).throw new NotFoundException($model)).fruitcake/laravel-cors: May need exception whitelisting.laravel/fortify: Auth exceptions might need customization.render() methods in Handler.php).Handler first.CHANGELOG.md for internal exception format updates.composer.json (e.g., ^1.0).EXCEPTIONS.md file detailing:
ValidationException, UnauthorizedException).throw new ForbiddenException()).request->input()).error field in favor of details).shouldReport() in Handler to skip logging for expected errors (e.g., 404s).trace_id for cross-service debugging.company/exceptions).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Package abandoned | Incompatible updates | Fork or switch to symfony/http-foundation |
| Exception format breaks clients | API consumers see malformed errors | Version error responses (e.g., v1/v2 routes) |
| Overuse of exceptions | Performance degradation | Enforce via code reviews (e.g., "use exceptions for errors only") |
| Missing localization | Errors in wrong language | Extend package or use Laravel’s trans() |
throw new UnprocessableEntityException($validator->errors())).render()).PaymentFailedException).README (if available) and internal EXCEPTIONS.md.## Throwing Exceptions
```php
// Bad: Using generic HTTP exceptions
abort(400, 'Invalid data');
// Good: Using domain-specific exceptions
throw new InvalidDataException($request->input());
abort() or custom Handler overrides.How can I help you explore Laravel packages today?