{"title":"Errors & Error Handling","slug":"errors","category":"api","summary":"HTTP ステータスコード、エラーレスポンス形式、よくあるエラーからの復旧方法。","audience":["human","llm"],"tags":["api","errors","troubleshooting","http"],"difficulty":"beginner","updated":"2026-06-27","word_count":229,"read_minutes":1,"llm_context":"Error format: { statusCode, error, message, docs? }\nCommon errors: 401 (auth), 404 (wrong path), 429 (rate limit), 500 (server)\n401 → check Mind Key/JWT, see /docs/getting-started/authentication\n404 → wrong path, GET /endpoints for valid list, do NOT guess paths\n429 → rate limited (?key= is 60/min), use Bearer header instead\n500 → server error, retry with backoff, check /health\ndocs field in error response links to relevant documentation.\n","lang":"ja","translated":true,"requested_lang":"ja","content_markdown":"\n# Errors & Error Handling\n\nSynapse は標準的な HTTP ステータスコードと一貫したエラーレスポンス形式を使用します。本ページではエラーの解釈と復旧方法を説明します。\n\n## エラーレスポンス形式\n\nすべてのエラーは以下の構造の JSON を返します。\n\n```json\n{\n  \"statusCode\": 401,\n  \"error\": \"Unauthorized\",\n  \"message\": \"Mind Key fehlt oder ungültig.\",\n  \"docs\": \"https://synapse.schaefer.zone/docs/getting-started/authentication\"\n}\n```\n\n| フィールド | 説明 |\n|-------|-------------|\n| `statusCode` | HTTP ステータスコード |\n| `error` | HTTP ステータス名 |\n| `message` | 人間が読めるエラーの説明 |\n| `docs` | 関連ドキュメントの URL（該当する場合） |\n\n## HTTP ステータスコード\n\n### 200 OK\n\n成功。リクエストが正常に処理されました。\n\n### 201 Created\n\n成功。新しいリソースが作成されました（例：`POST /memory`）。\n\n### 204 No Content\n\n成功。レスポンスボディはありません（例：`DELETE /memory/:id`）。\n\n### 400 Bad Request\n\nリクエストの形式が不正です。よくある原因：\n\n- 必須 JSON フィールドの欠落\n- 無効な JSON 構文\n- 無効な enum 値（例：カテゴリの誤り）\n\n```json\n{\n  \"statusCode\": 400,\n  \"error\": \"Bad Request\",\n  \"message\": \"category must be one of: identity, preference, fact, project, skill, mistake, context, note, credentials\"\n}\n```\n\n**対策：** リクエストボディを API ドキュメントと照合してください。すべての必須フィールドが存在し、有効な値であることを確認します。\n\n### 401 Unauthorized\n\n認証に失敗しました。よくある原因：\n\n- `Authorization` ヘッダーの欠落\n- 無効な Mind Key または JWT\n- Mind Key が必要な場所で JWT を使用（またはその逆）\n\n```json\n{\n  \"statusCode\": 401,\n  \"error\": \"Unauthorized\",\n  \"message\": \"Mind Key fehlt oder ungültig.\",\n  \"docs\": \"https://synapse.schaefer.zone/docs/getting-started/authentication\"\n}\n```\n\n**対策：** トークンを確認してください。[Authentication](/docs/getting-started/authentication) を参照。\n\n### 403 Forbidden\n\n認証は成功していますが、このアクションの実行が許可されていません。よくある原因：\n\n- 他のユーザーの mind を削除しようとした\n- Mind Key でメモリを検証しようとした（JWT が必要）\n- mind が無効化されている\n\n**対策：** このエンドポイントに対して正しいトークン種別を使用しているか確認してください。\n\n### 404 Not Found\n\n要求されたパスまたはリソースが存在しません。\n\n> [!CRITICAL]\n> **エンドポイントのパスを推測しないでください。** `GET /endpoints` にリストされたパスのみが存在します。404 が返された場合は、誤ったパスを使用しています。\n\n```json\n{\n  \"statusCode\": 404,\n  \"error\": \"Not Found\",\n  \"message\": \"Route GET /memory/list not found\",\n  \"docs\": \"https://synapse.schaefer.zone/docs/api/errors\"\n}\n```\n\n**対策：** `GET /endpoints` を呼び出して有効なエンドポイントのリストを確認してください。URL をリストと文字単位で比較してください。\n\n### 409 Conflict\n\nリクエストが既存の状態と競合しています。よくある原因：\n\n- 既に存在するメールアドレスで登録しようとした\n- Webhook URL の重複\n\n**対策：** 別の値を使用するか、`PUT` で既存リソースを更新してください。\n\n### 429 Too Many Requests\n\nレート制限に達しました。`?key=` クエリパラメータ認証（60 回/分）にのみ適用されます。\n\n```json\n{\n  \"statusCode\": 429,\n  \"error\": \"Too Many Requests\",\n  \"message\": \"Rate limit exceeded. Use Authorization header for unlimited access.\"\n}\n```\n\nレスポンスヘッダー：\n\n```\nX-RateLimit-Limit: 60\nX-RateLimit-Remaining: 0\nRetry-After: 42\n```\n\n**対策：** `Authorization: Bearer` ヘッダーに切り替える（レート制限なし）、または `Retry-After` 秒待機してください。\n\n### 500 Internal Server Error\n\nサーバーエラーです。本来発生すべきではありません。発生した場合はバグです。\n\n**対策：**\n\n1. 指数バックオフで再試行（1 秒、2 秒、4 秒、8 秒）\n2. `GET /health` でサーバー稼働状況を確認\n3. 持続する場合はエラーを報告\n\n### 503 Service Unavailable\n\nサーバーが一時的に停止しています（デプロイ中やデータベースマイグレーション中など）。\n\n**対策：** 待機して再試行してください。`GET /health` を確認。\n\n## 復旧パターン\n\n### 指数バックオフでの再試行\n\n```python\nimport time\nimport requests\n\ndef call_with_retry(url, max_retries=3):\n    for attempt in range(max_retries):\n        try:\n            r = requests.get(url, headers={\"Authorization\": f\"Bearer {KEY}\"})\n            if r.status_code == 429:\n                wait = int(r.headers.get(\"Retry-After\", 60))\n                time.sleep(wait)\n                continue\n            if r.status_code >= 500:\n                time.sleep(2 ** attempt)\n                continue\n            return r\n        except requests.RequestException:\n            time.sleep(2 ** attempt)\n    raise Exception(f\"Failed after {max_retries} retries\")\n```\n\n### 認証エラーの処理\n\n```python\ndef safe_call(url, key):\n    r = requests.get(url, headers={\"Authorization\": f\"Bearer {key}\"})\n    if r.status_code == 401:\n        # Mind Key invalid — alert user\n        raise AuthError(\"Mind Key invalid or expired\")\n    return r\n```\n\n## よくあるエラーシナリオ\n\n### \"Mind Key fehlt oder ungültig\"\n\n- `Authorization` ヘッダーを忘れた\n- `?key=` を使用したがキーが間違っている\n- Mind Key が必要な場所で JWT を使用している\n\n### \"Route not found\"\n\n- 存在しないパスを推測した\n- 動詞を誤使用（例：`GET /memory` と `POST /memory`）\n- `GET /endpoints` で有効なパスを確認\n\n### \"Rate limit exceeded\"\n\n- `?key=` を使用して 60 回/分を超えた\n- `Authorization: Bearer` ヘッダーに切り替える\n\n## 次のステップ\n\n- [Authentication](/docs/getting-started/authentication)\n- [API Overview](/docs/api/overview)\n- [Rate Limits](/docs/api/rate-limits)\n","content_html":"<h1>Errors &amp; Error Handling</h1>\n<p>Synapse は標準的な HTTP ステータスコードと一貫したエラーレスポンス形式を使用します。本ページではエラーの解釈と復旧方法を説明します。</p>\n<h2>エラーレスポンス形式</h2>\n<p>すべてのエラーは以下の構造の JSON を返します。</p>\n<pre><code class=\"hljs language-json\"><span class=\"hljs-punctuation\">{</span>\n  <span class=\"hljs-attr\">&quot;statusCode&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-number\">401</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;error&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;Unauthorized&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;message&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;Mind Key fehlt oder ungültig.&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;docs&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;https://synapse.schaefer.zone/docs/getting-started/authentication&quot;</span>\n<span class=\"hljs-punctuation\">}</span></code></pre><table>\n<thead>\n<tr>\n<th>フィールド</th>\n<th>説明</th>\n</tr>\n</thead>\n<tbody><tr>\n<td><code>statusCode</code></td>\n<td>HTTP ステータスコード</td>\n</tr>\n<tr>\n<td><code>error</code></td>\n<td>HTTP ステータス名</td>\n</tr>\n<tr>\n<td><code>message</code></td>\n<td>人間が読めるエラーの説明</td>\n</tr>\n<tr>\n<td><code>docs</code></td>\n<td>関連ドキュメントの URL（該当する場合）</td>\n</tr>\n</tbody></table>\n<h2>HTTP ステータスコード</h2>\n<h3>200 OK</h3>\n<p>成功。リクエストが正常に処理されました。</p>\n<h3>201 Created</h3>\n<p>成功。新しいリソースが作成されました（例：<code>POST /memory</code>）。</p>\n<h3>204 No Content</h3>\n<p>成功。レスポンスボディはありません（例：<code>DELETE /memory/:id</code>）。</p>\n<h3>400 Bad Request</h3>\n<p>リクエストの形式が不正です。よくある原因：</p>\n<ul>\n<li>必須 JSON フィールドの欠落</li>\n<li>無効な JSON 構文</li>\n<li>無効な enum 値（例：カテゴリの誤り）</li>\n</ul>\n<pre><code class=\"hljs language-json\"><span class=\"hljs-punctuation\">{</span>\n  <span class=\"hljs-attr\">&quot;statusCode&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-number\">400</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;error&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;Bad Request&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;message&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;category must be one of: identity, preference, fact, project, skill, mistake, context, note, credentials&quot;</span>\n<span class=\"hljs-punctuation\">}</span></code></pre><p><strong>対策：</strong> リクエストボディを API ドキュメントと照合してください。すべての必須フィールドが存在し、有効な値であることを確認します。</p>\n<h3>401 Unauthorized</h3>\n<p>認証に失敗しました。よくある原因：</p>\n<ul>\n<li><code>Authorization</code> ヘッダーの欠落</li>\n<li>無効な Mind Key または JWT</li>\n<li>Mind Key が必要な場所で JWT を使用（またはその逆）</li>\n</ul>\n<pre><code class=\"hljs language-json\"><span class=\"hljs-punctuation\">{</span>\n  <span class=\"hljs-attr\">&quot;statusCode&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-number\">401</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;error&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;Unauthorized&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;message&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;Mind Key fehlt oder ungültig.&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;docs&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;https://synapse.schaefer.zone/docs/getting-started/authentication&quot;</span>\n<span class=\"hljs-punctuation\">}</span></code></pre><p><strong>対策：</strong> トークンを確認してください。<a href=\"/docs/getting-started/authentication\">Authentication</a> を参照。</p>\n<h3>403 Forbidden</h3>\n<p>認証は成功していますが、このアクションの実行が許可されていません。よくある原因：</p>\n<ul>\n<li>他のユーザーの mind を削除しようとした</li>\n<li>Mind Key でメモリを検証しようとした（JWT が必要）</li>\n<li>mind が無効化されている</li>\n</ul>\n<p><strong>対策：</strong> このエンドポイントに対して正しいトークン種別を使用しているか確認してください。</p>\n<h3>404 Not Found</h3>\n<p>要求されたパスまたはリソースが存在しません。</p>\n<div class=\"callout callout-critical\">**エンドポイントのパスを推測しないでください。** `GET /endpoints` にリストされたパスのみが存在します。404 が返された場合は、誤ったパスを使用しています。</div><pre><code class=\"hljs language-json\"><span class=\"hljs-punctuation\">{</span>\n  <span class=\"hljs-attr\">&quot;statusCode&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-number\">404</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;error&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;Not Found&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;message&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;Route GET /memory/list not found&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;docs&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;https://synapse.schaefer.zone/docs/api/errors&quot;</span>\n<span class=\"hljs-punctuation\">}</span></code></pre><p><strong>対策：</strong> <code>GET /endpoints</code> を呼び出して有効なエンドポイントのリストを確認してください。URL をリストと文字単位で比較してください。</p>\n<h3>409 Conflict</h3>\n<p>リクエストが既存の状態と競合しています。よくある原因：</p>\n<ul>\n<li>既に存在するメールアドレスで登録しようとした</li>\n<li>Webhook URL の重複</li>\n</ul>\n<p><strong>対策：</strong> 別の値を使用するか、<code>PUT</code> で既存リソースを更新してください。</p>\n<h3>429 Too Many Requests</h3>\n<p>レート制限に達しました。<code>?key=</code> クエリパラメータ認証（60 回/分）にのみ適用されます。</p>\n<pre><code class=\"hljs language-json\"><span class=\"hljs-punctuation\">{</span>\n  <span class=\"hljs-attr\">&quot;statusCode&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-number\">429</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;error&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;Too Many Requests&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;message&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;Rate limit exceeded. Use Authorization header for unlimited access.&quot;</span>\n<span class=\"hljs-punctuation\">}</span></code></pre><p>レスポンスヘッダー：</p>\n<pre><code class=\"hljs language-plaintext\">X-RateLimit-Limit: 60\nX-RateLimit-Remaining: 0\nRetry-After: 42</code></pre><p><strong>対策：</strong> <code>Authorization: Bearer</code> ヘッダーに切り替える（レート制限なし）、または <code>Retry-After</code> 秒待機してください。</p>\n<h3>500 Internal Server Error</h3>\n<p>サーバーエラーです。本来発生すべきではありません。発生した場合はバグです。</p>\n<p><strong>対策：</strong></p>\n<ol>\n<li>指数バックオフで再試行（1 秒、2 秒、4 秒、8 秒）</li>\n<li><code>GET /health</code> でサーバー稼働状況を確認</li>\n<li>持続する場合はエラーを報告</li>\n</ol>\n<h3>503 Service Unavailable</h3>\n<p>サーバーが一時的に停止しています（デプロイ中やデータベースマイグレーション中など）。</p>\n<p><strong>対策：</strong> 待機して再試行してください。<code>GET /health</code> を確認。</p>\n<h2>復旧パターン</h2>\n<h3>指数バックオフでの再試行</h3>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import</span> time\n<span class=\"hljs-keyword\">import</span> requests\n\n<span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">call_with_retry</span>(<span class=\"hljs-params\">url, max_retries=<span class=\"hljs-number\">3</span></span>):\n    <span class=\"hljs-keyword\">for</span> attempt <span class=\"hljs-keyword\">in</span> <span class=\"hljs-built_in\">range</span>(max_retries):\n        <span class=\"hljs-keyword\">try</span>:\n            r = requests.get(url, headers={<span class=\"hljs-string\">&quot;Authorization&quot;</span>: <span class=\"hljs-string\">f&quot;Bearer <span class=\"hljs-subst\">{KEY}</span>&quot;</span>})\n            <span class=\"hljs-keyword\">if</span> r.status_code == <span class=\"hljs-number\">429</span>:\n                wait = <span class=\"hljs-built_in\">int</span>(r.headers.get(<span class=\"hljs-string\">&quot;Retry-After&quot;</span>, <span class=\"hljs-number\">60</span>))\n                time.sleep(wait)\n                <span class=\"hljs-keyword\">continue</span>\n            <span class=\"hljs-keyword\">if</span> r.status_code &gt;= <span class=\"hljs-number\">500</span>:\n                time.sleep(<span class=\"hljs-number\">2</span> ** attempt)\n                <span class=\"hljs-keyword\">continue</span>\n            <span class=\"hljs-keyword\">return</span> r\n        <span class=\"hljs-keyword\">except</span> requests.RequestException:\n            time.sleep(<span class=\"hljs-number\">2</span> ** attempt)\n    <span class=\"hljs-keyword\">raise</span> Exception(<span class=\"hljs-string\">f&quot;Failed after <span class=\"hljs-subst\">{max_retries}</span> retries&quot;</span>)</code></pre><h3>認証エラーの処理</h3>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">safe_call</span>(<span class=\"hljs-params\">url, key</span>):\n    r = requests.get(url, headers={<span class=\"hljs-string\">&quot;Authorization&quot;</span>: <span class=\"hljs-string\">f&quot;Bearer <span class=\"hljs-subst\">{key}</span>&quot;</span>})\n    <span class=\"hljs-keyword\">if</span> r.status_code == <span class=\"hljs-number\">401</span>:\n        <span class=\"hljs-comment\"># Mind Key invalid — alert user</span>\n        <span class=\"hljs-keyword\">raise</span> AuthError(<span class=\"hljs-string\">&quot;Mind Key invalid or expired&quot;</span>)\n    <span class=\"hljs-keyword\">return</span> r</code></pre><h2>よくあるエラーシナリオ</h2>\n<h3>&quot;Mind Key fehlt oder ungültig&quot;</h3>\n<ul>\n<li><code>Authorization</code> ヘッダーを忘れた</li>\n<li><code>?key=</code> を使用したがキーが間違っている</li>\n<li>Mind Key が必要な場所で JWT を使用している</li>\n</ul>\n<h3>&quot;Route not found&quot;</h3>\n<ul>\n<li>存在しないパスを推測した</li>\n<li>動詞を誤使用（例：<code>GET /memory</code> と <code>POST /memory</code>）</li>\n<li><code>GET /endpoints</code> で有効なパスを確認</li>\n</ul>\n<h3>&quot;Rate limit exceeded&quot;</h3>\n<ul>\n<li><code>?key=</code> を使用して 60 回/分を超えた</li>\n<li><code>Authorization: Bearer</code> ヘッダーに切り替える</li>\n</ul>\n<h2>次のステップ</h2>\n<ul>\n<li><a href=\"/docs/getting-started/authentication\">Authentication</a></li>\n<li><a href=\"/docs/api/overview\">API Overview</a></li>\n<li><a href=\"/docs/api/rate-limits\">Rate Limits</a></li>\n</ul>\n","urls":{"html":"/docs/api/errors","text":"/docs/api/errors?format=text","json":"/docs/api/errors?format=json","llm":"/docs/api/errors?format=llm"},"translations_available":["en","zh","hi","es","fr","ar","pt","ru","ja","de","it","ko","nl","pl","tr","sv","vi","th","id","uk"]}