Custom exceptions with static factories and HTTP responses. Use when working with error handling, custom exceptions, or when user mentions exceptions, custom exception, error handling, HTTP exceptions.
/plugin marketplace add leeovery/claude-laravel/plugin install leeovery-claude-laravel@leeovery/claude-laravelThis skill inherits all available tools. When active, it can use any tool Claude has access to.
references/Httpable.phpCustom exceptions use static factory methods and implement HttpExceptionInterface.
Related guides:
<?php
declare(strict_types=1);
namespace App\Exceptions;
use App\Exceptions\Concerns\Httpable;
use App\Models\Order;
use Exception;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
class OrderException extends Exception implements HttpExceptionInterface
{
use Httpable;
public static function notFound(string|int $orderId): self
{
return new self("Order {$orderId} not found.", 404);
}
public static function cannotCancelOrder(Order $order): self
{
return new self(
"Order {$order->uuid} cannot be cancelled in its current state.",
400
);
}
public static function insufficientStock(string $productName): self
{
return new self(
"Insufficient stock for product: {$productName}",
422
);
}
public static function paymentFailed(string $reason): self
{
return new self("Payment failed: {$reason}", 402);
}
}
// In actions
throw OrderException::notFound($orderId);
throw OrderException::cannotCancelOrder($order);
throw OrderException::insufficientStock($product->name);
class CancelOrderAction
{
public function __invoke(Order $order): Order
{
throw_unless(
$order->canBeCancelled(),
OrderException::cannotCancelOrder($order)
);
// Continue with cancellation
}
}
class ProcessOrderAction
{
public function __invoke(Order $order): void
{
$this->guard($order);
// Process order
}
private function guard(Order $order): void
{
throw_unless(
$order->isPending(),
OrderException::cannotProcessOrder($order)
);
throw_unless(
$order->hasItems(),
OrderException::orderHasNoItems($order)
);
}
}
Named constructors for specific exceptions:
public static function notFound(string|int $orderId): self
{
return new self("Order {$orderId} not found.", 404);
}
Pass status as second constructor parameter:
new self("Message", 404); // Not Found
new self("Message", 400); // Bad Request
new self("Message", 422); // Unprocessable Entity
new self("Message", 403); // Forbidden
Include context in error messages:
"Order {$order->uuid} cannot be cancelled"
"Insufficient stock for product: {$productName}"
Implement interface for automatic HTTP error responses:
class OrderException extends Exception implements HttpExceptionInterface
{
use Httpable;
}
400 - Bad Request (business rule violation)402 - Payment Required403 - Forbidden (authorization failed)404 - Not Found422 - Unprocessable Entity (validation failed)500 - Internal Server Errorapp/Exceptions/
├── OrderException.php
├── PaymentException.php
├── UserException.php
└── Concerns/
└── Httpable.php
Exceptions should:
HttpExceptionInterface{Entity}ExceptionUse for business rule violations and error conditions.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.