Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Api Exception Bundle Laravel Package

app-verk/api-exception-bundle

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:
    • Aligns with modern API standards (RFC 7807 problem+json) for consistent error responses.
    • Lightweight (~100 LOC) and focused on a single responsibility (exception normalization).
    • Compatible with Symfony’s event-driven architecture (via ApiExceptionSubscriber).
    • Supports customization via ResponseFactoryInterface, enabling alignment with existing error schemas (e.g., OpenAPI, custom wrappers).
  • Cons:
    • Tight coupling to Symfony: Not framework-agnostic (e.g., no PSR-15 middleware support), limiting reuse in non-Symfony PHP apps.
    • Limited extensibility: No built-in support for:
      • Dynamic error enrichment (e.g., injecting user context, logs).
      • Non-JSON responses (e.g., XML, HTML fallbacks).
      • Global exception modifiers (e.g., masking sensitive data in production).
    • Deprecated Symfony versions: Requires SensioFrameworkExtraBundle v5.3/6.x, which may conflict with newer Symfony 6/7 apps using Attribute routing.

Integration Feasibility

  • Symfony 3.3+: Works out-of-the-box for legacy apps but may require adjustments for:
    • Symfony 6/7: SensioFrameworkExtraBundle is deprecated; migration to Attribute routing may break subscriber binding.
    • Monolithic vs. Microservices: Overkill for microservices (prefer PSR-15 middleware like zend-expressive-problem-details).
  • Non-Symfony PHP: Requires significant refactoring (e.g., manual event listeners, custom error handlers).
  • Existing Error Handling:
    • Conflict Risk: May override existing JsonResponse logic or custom exception handlers.
    • Testing Impact: Requires updating tests expecting raw exceptions (now wrapped in problem+json).

Technical Risk

Risk Area Severity Mitigation Strategy
Symfony Version Drift High Pin sensio/framework-extra-bundle to exact version; test with target Symfony major version.
Customization Complexity Medium Document ResponseFactoryInterface extensions; provide a base class for common use cases (e.g., adding request_id).
Performance Overhead Low Minimal (event subscriber adds ~1ms latency).
Maintenance Burden Medium Bundle is abandoned (last release 2020); fork or replace if critical.
Security Misconfig High Ensure paths_excluded covers sensitive endpoints (e.g., /debug).

Key Questions

  1. Symfony Ecosystem:
    • Are you using Symfony 6/7? If yes, how will you handle the SensioFrameworkExtraBundle deprecation?
    • Do you have existing global exception handlers (e.g., ErrorListener) that could conflict?
  2. Error Schema Requirements:
    • Does your API require extensions to RFC 7807 (e.g., validation_errors, links)?
    • Are there non-JSON response needs (e.g., HTML for web clients)?
  3. Observability:
    • How will you log/analyze these normalized errors (e.g., Sentry, Datadog)?
    • Do you need to preserve original exception traces in non-production environments?
  4. Team Skills:
    • Is the team familiar with Symfony event subscribers and ResponseFactory patterns?
  5. Alternatives:

Integration Approach

Stack Fit

  • Symfony 3.3–5.x: Excellent fit for monolithic apps needing RFC 7807 compliance.
  • Symfony 6/7: Partial fit—requires:
    • Replacing sensio/framework-extra-bundle with Attribute routing.
    • Potentially forking the bundle to update dependencies.
  • Non-Symfony PHP:
  • Microservices:
    • Avoid. Use lightweight middleware (e.g., zend-expressive-problem-details) or framework-native solutions (e.g., Laravel’s ProblemException).

Migration Path

  1. Assessment Phase:
    • Audit existing exception handlers (e.g., JsonResponse wrappers, custom listeners).
    • Verify Symfony version compatibility (run composer why-not symfony/framework-bundle:^6.0).
  2. Pilot Integration:
    • Install in a non-production environment:
      composer require app-verk/api-exception-bundle --dev
      
    • Add to AppKernel.php (Symfony <5.1) or config/bundles.php (Symfony ≥5.1):
      AppVerk\ApiExceptionBundle\AppVerkApiExceptionBundle::class => ['all' => true],
      
    • Configure minimal settings in config/packages/app_verk_api_exception.yaml:
      app_verk_api_exception:
          enabled: true
          paths_excluded: ['/admin/', '/_error']
      
  3. Customization:
    • Implement ResponseFactoryInterface if schema deviations are needed (e.g., adding timestamp):
      // src/Factory/CustomResponseFactory.php
      class CustomResponseFactory implements ResponseFactoryInterface {
          public function createResponse(ApiProblemInterface $problem) {
              $data = $problem->toArray();
              $data['timestamp'] = (new \DateTime())->format(\DATE_RFC3339);
              return new JsonResponse($data, $problem->getStatusCode(), [], true);
          }
      }
      
    • Update config to use the custom factory:
      app_verk_api_exception:
          response_factory: App\Factory\CustomResponseFactory
      
  4. Testing:
    • Verify all error paths return application/problem+json:
      $this->client->request('GET', '/nonexistent');
      $this->assertEquals('application/problem+json', $response->headers->get('Content-Type'));
      
    • Test excluded paths still return raw responses.
  5. Rollout:
    • Gradually enable for critical endpoints (e.g., /api/*).
    • Monitor error rates (e.g., Sentry) for regressions.

Compatibility

Component Compatibility Notes
Symfony 3.3–5.x Full support.
Symfony 6/7 Breaking: SensioFrameworkExtraBundle deprecated; requires attribute routing.
API Platform Conflict: May override API Platform’s built-in error formatting.
Custom Exception Handlers Risk: Subscriber may override JsonResponse logic. Test thoroughly.
Guzzle HTTP Client Note: Client expects problem+json; ensure GuzzleHttp\Exception\ClientException handling aligns.

Sequencing

  1. Phase 1: Basic integration (default problem+json).
  2. Phase 2: Customize response schema (if needed).
  3. Phase 3: Exclude non-API paths (e.g., /admin).
  4. Phase 4: Extend for edge cases (e.g., validation errors, auth failures).
  5. Phase 5: Deprecate old error formats (if migrating from custom schemas).

Operational Impact

Maintenance

  • Pros:
    • Minimal moving parts (single bundle, one subscriber).
    • MIT license allows forking if needed.
  • Cons:
    • Abandoned Project: No updates since 2020; security patches unlikely.
    • Symfony Lock-in: Tied to Symfony’s event system; hard to port.
    • Customization Debt: Extensions (e.g., dynamic fields) require manual maintenance.
  • Recommendations:
    • Fork the repo to apply critical fixes (e.g., Symfony 6+ support).
    • Document customizations in a CONTRIBUTING.md for future maintainers.

Support

  • Debugging:
    • Pros: Centralized error format eases client-side parsing.
    • Cons:
      • Original exception traces may be lost in production (configure debug: false).
      • Stack traces in problem+json require explicit inclusion (not default).
  • Tools:
    • Sentry/Loggly: Ensure these tools parse problem+json (may need custom SDK config).
    • API Gateways: Verify tools like Kong or Apigee handle problem+json correctly.
  • Client-Side Impact:
    • Frontend teams must update error handlers to
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui