L
laravel:exception-handling-and-logging
About laravel:exception-handling-and-logging
A Laravel development skill for handling exceptions and logs with actionable context. It covers domain-specific exceptions, structured logging, separate channels for noisy logs, and API-appropriate error responses.
Key features
- 01Define domain-specific exceptions
- 02Add structured context to logs
- 03Avoid logging secrets
- 04Separate noisy log channels
- 05Render API-appropriate responses
Use cases
- 01Logging expected domain errors
- 02Returning API responses for missing models
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ jpcaparas/ superpowers-laravel --skill laravel:exception-handling-and-loggingAfter installing, type/laravel:exception-handling-and-loggingin Claude Code to confirm it loaded.
Details
From the project READMEException Handling and Logging
Treat errors as first-class signals; provide context and paths to remediation.
Commands
// app/Exceptions/Handler.php
public function register(): void
{
$this->reportable(function (DomainException $e) {
Log::warning('domain exception', ['code' => $e->getCode()]);
});
$this->renderable(function (ModelNotFoundException $e, $request) {
if ($request->expectsJson()) {
return response()->json(['message' => 'Not Found'], 404);
}
});
}
Patterns
- Use domain-specific exceptions for expected error paths
- Add structured context to logs; avoid logging secrets
- Route noisy logs to separate channels; keep defaults actionable
- Convert to API-appropriate responses in
renderable()
Comments
Markdown supported