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.
error, message, and code fields).try/catch blocks.Log facade) for unified error tracking.FormRequest validation failures with detailed JSON responses.symfony/http-foundation, symfony/validator) or are willing to adapt the bundle’s logic.try/catch blocks, inconsistent response()->json() calls).App\Exceptions\Handler with custom render() logic.spatie/laravel-fractal for API response standardization.api-platform/core or modern alternatives.webonyx/graphql-php instead)."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."
"This Symfony2 bundle centralizes API exception handling with configurable JSON responses, stack trace control, and validation error support. Key benefits for Laravel:
try/catch blocks with a single App\Exceptions\Handler override.Validator for form errors or custom exception classes.Validator) if already in your stack.Tradeoffs:
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."*
"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!"*
How can I help you explore Laravel packages today?