axy/errors
axy/errors is a PHP 8.1+ helper for defining and organizing exception classes. Provides common exception structures, basic error classes, default messages, backtrace truncation, and global options to standardize error handling across projects.
Error → Logic/Runtime), which aligns well with Laravel’s existing exception handling (e.g., Illuminate\Contracts\Container\BindingResolutionException). This allows for granular error categorization and consistent error propagation.NotFound, InvalidValue, ReadOnly) mirrors Laravel’s built-in exceptions (e.g., ModelNotFoundException, ValidationException), reducing cognitive overhead for developers.axy/backtrace integration for truncating stack traces is valuable in Laravel for hiding framework internals (e.g., service container, middleware) from end users, improving error messages in production.try-catch blocks can leverage the new exceptions without breaking changes.Error interface) is compatible with Laravel’s dependency injection and middleware stacks, enabling seamless integration with frameworks like Laravel\Pipeline.InvalidFormat, NotValid, and TypingError exceptions align perfectly with Laravel’s validation layer, offering more expressive error handling for form requests or API payloads.catch blocks to handle the new hierarchy (e.g., axy\errors\Logic vs. Runtime). A migration path (see Integration Approach) can mitigate this.App\Errors\InvalidConfig), which could conflict with existing Laravel conventions if not scoped properly (e.g., App\Exceptions).App\Errors or App\Exceptions to avoid conflicts with Laravel’s built-in exceptions?App\Services)?FormRequest validation layer (e.g., custom error bags)?getTrace() be preserved for admins?Symfony\Component\HttpKernel\Exception\HttpException?App\Exceptions\Handler), allowing customization of HTTP responses, logging, and rendering.InvalidFormat and NotValid can replace or extend Laravel’s ValidationException, providing more context for API clients.App\Http\Middleware\ValidateExceptions) to standardize error responses.Disabled and AdapterNotDefined exceptions are ideal for service container errors (e.g., binding resolution failures).App\Services\Payment\InvalidConfig).axy\errors\Logic/Runtime (e.g., App\Exceptions\InvalidUserInput extends axy\errors\InvalidValue).class MyException extends \RuntimeException implements axy\errors\Error {
use axy\errors\Traits\TruncatedTrace;
}
App\Exceptions\Handler with the new hierarchy (e.g., catch axy\errors\Error as the base case).catch blocks in tests and business logic incrementally.spatie/laravel-permission, laravel/breeze), as the package focuses on exceptions.composer require axy/errors
namespace App\Exceptions;
use axy\errors\Logic;
use axy\errors\Traits\TruncatedTrace;
class AppException extends Logic {
use TruncatedTrace;
}
App\Exceptions\Handler to render new exceptions:
public function render($request, Throwable $exception) {
if ($exception instanceof axy\errors\Error) {
return response()->json([
'error' => $exception->getMessage(),
'code' => $exception->getCode(),
'type' => get_class($exception),
], $exception->getCode());
}
return parent::render($request, $exception);
}
RuntimeException, InvalidArgumentException, etc., with the new hierarchy (e.g., InvalidFormat instead of InvalidArgumentException for validation errors).NotFound, InvalidValue).InvalidFormat includes $value and $type) improve debugging and API documentation.getTruncatedTrace().Logic vs. Runtime) and documentation (e.g., org.md) reduce onboarding time for new team members.$container, $service), making it easier to diagnose issues in distributed systems (e.g., microservices).Disabled and ActionNotAllowed help define clear API contracts for consumers (e.g., "This endpoint is disabled in this environment").$howTruncateTrace as needed.axy\errors\Error instead of more specific exceptions (e.g., InvalidConfig), leading to broad error handling.Error).catch blocks to handle the new hierarchy may miss some edge cases in legacy code.How can I help you explore Laravel packages today?