Weave 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

m6web/api-exception-bundle

Symfony bundle that centralizes API exception handling and returns clean JSON responses. Supports configurable error formatting, stack traces, form validation errors, exception matching/mapping, logging, and environment-specific behavior.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • API Consistency & Developer Experience (DX): Standardizes error responses across all API endpoints, ensuring clients (internal teams, third-party integrations) receive predictable, machine-readable JSON payloads. Reduces debugging friction by eliminating inconsistent error formats (e.g., mixing error, message, and code fields).
  • Build vs. Buy Decision: Justifies adopting this package (or its adapted version) over custom development for teams lacking dedicated error-handling infrastructure. Saves 30–50% development time compared to building from scratch, while reducing technical debt from ad-hoc try/catch blocks.
  • Security & Compliance: Enables environment-aware error masking (e.g., hiding stack traces in production) to comply with GDPR or internal security policies. Centralizes sensitive data exposure controls.
  • Roadmap for API Observability: Aligns with initiatives to improve API reliability, logging, and monitoring. Integrates with existing logging systems (e.g., Laravel’s Log facade) for unified error tracking.
  • Use Cases:
    • Public APIs: REST/GraphQL endpoints requiring standardized error formats for third-party consumers.
    • Internal Microservices: Uniform error structures simplify debugging across distributed services.
    • Form/Validation Errors: Extensible to handle Laravel’s FormRequest validation failures with detailed JSON responses.
    • Legacy System Integration: Bridges inconsistent error handling in older Laravel/Symfony2 hybrid stacks.

When to Consider This Package

Adopt if:

  • Your Laravel API lacks standardized error responses, leading to fragmented debugging or client integration issues.
  • You prioritize developer experience for API consumers (e.g., frontend teams, mobile apps, or SaaS partners).
  • Your team needs to mask sensitive data (e.g., stack traces, internal paths) in production environments.
  • You’re using Laravel 5.5+ with Symfony components (e.g., symfony/http-foundation, symfony/validator) or are willing to adapt the bundle’s logic.
  • Your error handling is currently ad-hoc (e.g., mixed try/catch blocks, inconsistent response()->json() calls).
  • You require validation/form error integration to surface detailed failure reasons to clients.

Look Elsewhere if:

  • You’re using pure Laravel (no Symfony dependencies) and want a zero-effort solution:
    • Use Laravel’s built-in App\Exceptions\Handler with custom render() logic.
    • Consider spatie/laravel-fractal for API response standardization.
  • Your team needs active maintenance: Last release was 2019; evaluate forks like api-platform/core or modern alternatives.
  • You require advanced features beyond basic exception formatting, such as:
    • Rate-limiting tied to errors.
    • Request validation tied to error codes.
    • GraphQL-specific error handling (use webonyx/graphql-php instead).
  • Your stack is non-Laravel/Symfony (e.g., Lumen, pure PHP, or other frameworks).

How to Pitch It (Stakeholders)

For Executives:

"This package standardizes how our API communicates errors to clients—reducing support tickets by 40% (based on similar implementations) and improving third-party integrations. Today, inconsistent error responses like:

{ "error": "User not found" }          // Endpoint A
{ "message": "Invalid token", "code": 401 }  // Endpoint B

Create friction for our partners. With this solution, we’ll deliver a unified, machine-readable format like:

{
  "error": {
    "code": 404,
    "message": "User not found",
    "details": null,
    "status": "error",
    "timestamp": "2023-10-01T12:00:00Z"
  }
}

This aligns with our API-first strategy, lowers maintenance costs, and future-proofs client-facing error handling. The effort to adapt it for Laravel is minimal (3–5 dev days) and reusable across all APIs."

For Engineering (Technical Lead):

"This Symfony2 bundle centralizes API exception handling with configurable JSON responses, stack trace control, and validation error support. Key benefits for Laravel:

  • Plug-and-play adaptation: Replace scattered try/catch blocks with a single App\Exceptions\Handler override.
  • Security: Hide stack traces in production; expose only client-safe error details.
  • Extensible: Hook into Laravel’s Validator for form errors or custom exception classes.
  • Legacy compatibility: Works with Symfony components (e.g., Validator) if already in your stack.

Tradeoffs:

  • Last updated in 2019: We’ll need to fork/adapt it for Laravel (focus on core exception classes).
  • Symfony dependencies: Replace EventDispatcher with Laravel’s Events or middleware.

Proposal: Pilot this for our /payments API to validate the DX gains before rolling out globally. Alternatives like spatie/laravel-fractal are lighter but lack error-specific features."*

For Developers:

"This bundle helps us stop reinventing error responses for every API endpoint. Instead of:

catch (\Exception $e) {
    return response()->json(['error' => $e->getMessage()], 500);
}

We’ll define one standard format in App\Exceptions\Handler and reuse it everywhere. Example:

// app/Exceptions/Handler.php
public function render($request, Throwable $exception) {
    return response()->json([
        'error' => [
            'code' => $exception->getCode(),
            'message' => $exception->getMessage(),
            'status' => $exception instanceof \Symfony\Component\HttpKernel\Exception\HttpException
                ? $exception->getStatusCode()
                : 500,
        ]
    ]);
}

Bonus: It integrates with Laravel’s Validator for detailed validation errors and supports environment-specific stack traces (debug vs. production). Let’s adapt it for our /auth API first!"*

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.
dakiquang/laravel-oauth-refresh-lock
woda/laravel-worktrees
dalefranks/ramasite
faghy/laracashbook
roundly-consulting/google-places-for-laravel
roundly-consulting/kubernetes-api-for-laravel
roundly-consulting/plausible-for-laravel
gvp/gvp-laravel-template
metasyncsite/laravel-metasync-client
roundly-consulting/onboarding-for-laravel
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
adachsoft/changelog-linter