symfony/console, symfony/http-foundation) or Lumen (Symfony-compatible micro-framework). For vanilla Laravel, integration would require abstraction layers (e.g., middleware wrappers).ApiResponseLoader for flexible error formats (e.g., aligning with Laravel’s ProblemDetails or custom JSON structures).App\Exceptions\Handler, while this bundle uses Symfony’s EventListener. A custom middleware or exception handler wrapper would bridge the gap.Facade class).JsonResponse is compatible, but Symfony’s JsonResponse may need adaptation (e.g., headers, status codes).error_code (e.g., 40001123) may clash with Laravel’s HTTP status codes or existing error systems (e.g., Illuminate\Validation\ValidationException).kernel.exception) must be mocked or adapted for Laravel’s throw_orphan_exceptions or render() methods in Handler.spatie/laravel-problem-details) that could conflict?message, error_code) match the team’s API standards (e.g., OpenAPI, JSON:API)?error_code be prefixed (e.g., app.40001123) to avoid collisions?ApiExceptionListener add measurable overhead in high-throughput APIs?| Component | Laravel Equivalent | Integration Strategy |
|---|---|---|
Symfony EventListener |
Laravel Exception Handler |
Replace render() with a wrapper calling the bundle’s logic. |
JsonResponse |
Laravel JsonResponse |
Extend ApiResponseLoader to use Laravel’s Response factory. |
| Symfony DI Container | Laravel IoC | Use Symfony\Component\DependencyInjection via symfony/dependency-injection or alias services. |
kernel.exception Event |
Laravel Exception Hooks |
Subscribe to Laravel’s illuminate.exception or create a custom event. |
/api/health).// config/app.php
'providers' => [
// ...
App\Providers\DosFarmaExceptionsServiceProvider::class,
];
ExceptionHandler that delegates to the bundle:
public function render($request, Throwable $exception) {
return app(DosFarmaResponseLoader::class)->load($exception);
}
ApiResponseLoader to return Laravel-compatible responses:
class LaravelApiResponseLoader extends \DosFarma\ExceptionsBundle\Http\Service\ApiResponseLoader {
protected function createResponse(array $data, int $status): Response {
return new JsonResponse($data, $status);
}
}
HttpFoundation objects in Laravel tests.ExceptionHandler.public function handle($request, Closure $next) {
try {
return $next($request);
} catch (Throwable $e) {
return app(DosFarmaResponseLoader::class)->load($e);
}
}
spatie/laravel-problem-details or nesbot/carbon (if using Symfony’s DateTime). Resolve via priority configuration.ApiExceptionListener for a subset of exceptions (e.g., HttpException).ValidationException).JsonResponse instances with the bundle’s format.symfony/http-foundation:^5.4). Requires careful composer.json alignment.X-Powered-By: Laravel+DosFarma header to logs for clarity.ApiResponseLoader in Laravel.error_code schema may lock the API into this bundle. Mitigate by:
ErrorResponseLoader) for swappable implementations.ApiResponseLoader performs heavy operations (e.g., logging, analytics).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Bundle throws uncaught exceptions | 500 errors with no user-friendly response | Wrap bundle calls in try-catch in ExceptionHandler. |
| Symfony DI conflicts | Service registration failures | Use Symfony\Component\DependencyInjection\ContainerInterface explicitly. |
| Custom loader fails | Fallback to default Symfony response | Implement a fallback loader in the wrapper. |
| Laravel 10+ Symfony incompatibility | Integration breaks | Pin Symfony packages to compatible versions. |
HttpFoundation.ExceptionHandler implementation.How can I help you explore Laravel packages today?