feat: 例外クラスに構造化コンテキストとエラーコードを追加#125
Merged
KinjiKawaguchi merged 5 commits intodevelopfrom Mar 25, 2026
Merged
Conversation
全例外クラスを改善し、プログラムから扱いやすい構造化された情報を提供する。 - code: プログラムからの判別用エラーコード - category: VALIDATION / NOT_FOUND / CONFLICT / INVARIANT_VIOLATION 等の大分類 - context: 関連IDや値をプロパティとして取得可能に - hint: 利用者への解決ガイダンス - cause: ES2022 Error.cause によるエラーチェーン対応 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
readonly 初期化子はリテラル型として推論されるため、明示的な as const は冗長。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
EventNotFoundException に exhibitId が渡されていた意味的不整合を解消。 構造化コンテキストの信頼性を確保するため、exhibitId起点でイベントが 見つからないケース専用の例外クラスを追加。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
findByExhibitId でイベントが見つからない場合の例外を統一。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Comment on lines
+62
to
72
| export class ExhibitNotFoundFromExhibitIdException extends ApplicationException { | ||
| readonly code = "EXHIBIT_NOT_FOUND_BY_EXHIBIT_ID"; | ||
| readonly category = "NOT_FOUND"; | ||
| readonly context: { exhibitId: string }; | ||
| readonly hint = "展示IDが正しいか、またはイベントに登録済みか確認してください"; | ||
|
|
||
| constructor(exhibitId: string, options?: { cause?: unknown }) { | ||
| super(`指定された展示IDで展示が見つかりません: ${exhibitId}`, options); | ||
| this.context = { exhibitId }; | ||
| } | ||
| } |
There was a problem hiding this comment.
📝 Info: ExhibitNotFoundFromExhibitIdException is now dead code
The PR adds EventNotFoundByExhibitIdException and migrates all three use cases (GetMembersByExhibit, RegisterMemberToExhibit, RemoveMemberFromExhibit) to use it. However, the old ExhibitNotFoundFromExhibitIdException is still defined at src/application/exceptions/ApplicationExceptions.ts:62 and exported, but has zero remaining imports or usages in the codebase. It should be removed to avoid confusion with the similarly-named domain-level ExhibitNotFoundException.
Was this helpful? React with 👍 or 👎 to provide feedback.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
現状の例外はメッセージ文字列にIDや値が埋め込まれており、プログラムからの判別が困難だった。
呼び出し側が
catch後にエラー内容に応じた処理を行うには文字列パースが必要で、APIレスポンス構築やログ構造化に不便だった。What
全
DomainException/ApplicationExceptionサブクラスに以下のプロパティを追加:codeMEMBER_NOT_FOUND)categoryVALIDATION,NOT_FOUND,CONFLICT,INVARIANT_VIOLATION,PRECONDITION_FAILED)contexthintcause使用例
既存互換性
messageプロパティは従来通り人間向けメッセージを返すinstanceofによる分岐は従来通り動作catchコードは破壊されない備考
RegisterMemberToExhibit/RemoveMemberFromExhibitでEventNotFoundExceptionにexhibitIdが渡されている既存の意味的不整合があるが、スコープ外として今回は未修正Test plan
npm run typecheckパスnpm test全127テストパスnpm run build成功🤖 Generated with Claude Code