Skip to content

ユーザー作成時のエラーハンドリングを改善し、リソースエラーコードに基づく詳細なエラーメッセージを追加#69

Merged
yuito-it merged 5 commits intomainfrom
fix/user-create-dup-error
Mar 31, 2026
Merged

ユーザー作成時のエラーハンドリングを改善し、リソースエラーコードに基づく詳細なエラーメッセージを追加#69
yuito-it merged 5 commits intomainfrom
fix/user-create-dup-error

Conversation

@yuito-it
Copy link
Copy Markdown
Member

@yuito-it yuito-it commented Mar 30, 2026

Summary by CodeRabbit

バグ修正

  • ユーザー作成時のエラー表示を改善しました。ユーザー名やメールアドレスの競合時に、より具体的で識別しやすいエラーメッセージが返されるようになりました。
  • 認証失敗時のエラーハンドリングを一貫化し、予期しない 401 応答についても安定して適切なエラーが発生するようにしました。
  • 内部の整理を行い、動作や画面表示に影響を与えない軽微な変更を適用しました。

@yuito-it yuito-it added the kind/bug 何かが正常に動作しない label Mar 30, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8c923aef-11eb-4de2-a393-239d0c84acd7

📥 Commits

Reviewing files that changed from the base of the PR and between 5484bed and 01441d5.

📒 Files selected for processing (1)
  • src/classes/User.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/classes/User.ts

📝 Walkthrough

Walkthrough

インポート順序と型宣言の微調整が行われ、User.createのHTTP 409ハンドリングがレスポンスJSONのcodeに基づく具体的な競合エラー判定へ変更され、認証処理の401分岐が既知理由以外でも確実にInvalidCredentialsを投げるよう修正されました。

Changes

Cohort / File(s) Summary
インポート順・型指定
src/app/dashboard/page.tsx, src/components/Cards/OtherServices/index.tsx
アイコンやコンポーネントのimport順を整理。OtherServiceCardPropstype指定の型インポートに変更(page.tsx)。実行時ロジックは不変。
User クラスの409ハンドリング
src/classes/User.ts
User.createの409ブランチでレスポンスをJSON解析(安全なtry/catch)し、codeフィールドをResourceApiErrorCodesと照合してUsernameAlreadyExists/EmailAlreadyExists等の具体的な例外にマップするよう変更。
認証エラーの確定的な扱い
src/libs/authentication.ts
401レスポンスの処理で、既知のreasonに該当しない場合も確実にAuthenticationErrors.InvalidCredentialsをスローするよう変更(制御フローの明確化)。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed プルリクエストのタイトルは、ユーザー作成時のエラーハンドリング改善とリソースエラーコードに基づく詳細なエラーメッセージ追加という主要な変更を明確に説明しており、変更内容と完全に関連している。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/user-create-dup-error

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@yuito-it
Copy link
Copy Markdown
Member Author

@coderabbitai review now

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

@yuito-it: Sure! I'll start reviewing the PR now.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@yuito-it
Copy link
Copy Markdown
Member Author

@coderabbitai review now

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

@yuito-it: Sure! I'll start reviewing the PR now.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/classes/User.ts`:
- Around line 154-164: The 409 handling assumes response.json() yields an object
and directly accesses errorData.code, which can throw on non-object or parse
failure; wrap the JSON parse in a try/catch and defensively extract the code
(e.g., let code = parsed && typeof parsed === "object" ? parsed.code :
undefined), then switch on that code (checking equality with
ResourceApiErrorCodes.UsernameAlreadyExists / EmailAlreadyExists) and fall back
to throwing ResourceApiErrors.ResourceAlreadyExists for any unknown/absent code;
update the case 409 block in User.ts to use this safe parsing and fallback logic
around response.json()/errorData.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dad8866f-9bbf-4f42-ab24-1a8b80672f43

📥 Commits

Reviewing files that changed from the base of the PR and between b066b53 and 5484bed.

📒 Files selected for processing (4)
  • src/app/dashboard/page.tsx
  • src/classes/User.ts
  • src/components/Cards/OtherServices/index.tsx
  • src/libs/authentication.ts

@yuito-it yuito-it merged commit 4c0e9ef into main Mar 31, 2026
5 of 6 checks passed
@yuito-it yuito-it deleted the fix/user-create-dup-error branch March 31, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug 何かが正常に動作しない

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant