mcpField
L
laravel:exception-handling-and-logging

laravel:exception-handling-and-logging

github.com/jpcaparas開発157142 回インストール18 週間前に更新
リポジトリ

laravel:exception-handling-and-logging について

実行可能なコンテキストを伴う例外処理とログ記録を扱う Laravel 開発スキルです。ドメイン固有の例外、構造化ログ、ログの分離、APIに適したエラー応答を取り上げます。

主な機能

  1. 01ドメイン固有の例外を定義
  2. 02ログに構造化コンテキストを追加
  3. 03シークレットの記録を回避
  4. 04ノイズの多いログを分離
  5. 05API向けの応答を生成

活用シーン

  1. 01想定されるドメインエラーの記録
  2. 02モデル未検出時のAPI応答

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/jpcaparas/superpowers-laravel --skill laravel:exception-handling-and-logging

インストール後、Claude Code で/laravel:exception-handling-and-loggingを入力して読み込まれたか確認します。

詳細

例外処理とロギング

エラーを重要なシグナルとして扱い、コンテキストと解決への道筋を示します。

コマンド

// 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);
        }
    });
}

パターン

  • 想定されるエラーパスには、ドメイン固有の例外を使用します
  • ログに構造化されたコンテキストを追加し、シークレットの記録は避けます
  • ノイズの多いログは別のチャネルに振り分け、デフォルト設定では対応に役立つ情報を出力します
  • renderable() で API に適したレスポンスに変換します

コメント