Add typed exception hierarchy#21
Conversation
Introduces MontonioException base and four specific subtypes: MontonioApiException, MontonioNetworkException, MontonioAuthenticationException, and MontonioValidationException. Each carries typed context fields for consumer-friendly error handling. Closes #13 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughIntroduces a flat unchecked exception hierarchy for the Montonio SDK: Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
src/main/java/ee/bitweb/montonio/sdk/exception/MontonioApiException.java (1)
19-35: Consider treating blank strings as absent in message formatting.
nullis handled well, but empty/blankerrorCodeorerrorMessagemay still render awkward output ([]or trailing:). Normalising blanks would make messages cleaner in edge cases.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/java/ee/bitweb/montonio/sdk/exception/MontonioApiException.java` around lines 19 - 35, The message formatter formatMessage in MontonioApiException should treat empty or whitespace-only errorCode and errorMessage as absent: normalize both inputs (trim and check isEmpty or use StringUtils.isBlank) before building the StringBuilder, replace null checks with blank-aware checks so you avoid producing "[]", trailing ": " or stray spaces/punctuation, and ensure the conditional branches around appending the colon, brackets and space use these normalized booleans (e.g., hasErrorCode, hasErrorMessage) to decide what to append.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/plans/2026-04-10-typed-exception-hierarchy-design.md`:
- Line 21: Replace the phrase "hand-written" with "handwritten" in the table
cell that currently reads "Lombok `@Getter`; hand-written constructors" so the
text reads "Lombok `@Getter`; handwritten constructors"; update that exact
string wherever it appears (e.g., the table row under the "Boilerplate" column)
to fix the wording/spelling.
- Around line 25-31: The fenced code block showing the exception hierarchy lacks
a language hint; update the block by adding a language tag (e.g., "text") after
the opening triple backticks so the snippet renders correctly and satisfies
markdown linting — apply this change to the block containing MontonioException
and its subclasses (MontonioApiException, MontonioNetworkException,
MontonioAuthenticationException, MontonioValidationException).
In
`@src/main/java/ee/bitweb/montonio/sdk/exception/MontonioValidationException.java`:
- Around line 20-22: The formatMessage method in MontonioValidationException
currently inserts null or blank field names literally; update
formatMessage(String field, String message) to sanitize the field parameter
(e.g., treat null or blank as a default like "<unknown>" or omit the field
label) before building the string so the resulting message is not "null" or
empty; ensure the field-based constructor that calls formatMessage uses this
sanitized output so validation messages remain clear and consistent.
- Around line 10-18: MontonioValidationException currently has two constructors
that don't accept a cause, losing upstream Throwable context; add two additional
cause-aware constructors—one matching public MontonioValidationException(String
field, String message) but with a Throwable cause and one matching public
MontonioValidationException(String message) with a Throwable cause—each should
call super(formattedMessage, cause) (use formatMessage(field, message) for the
field variant) and set this.field appropriately so callers can wrap
parse/normalisation failures without losing the root cause.
---
Nitpick comments:
In `@src/main/java/ee/bitweb/montonio/sdk/exception/MontonioApiException.java`:
- Around line 19-35: The message formatter formatMessage in MontonioApiException
should treat empty or whitespace-only errorCode and errorMessage as absent:
normalize both inputs (trim and check isEmpty or use StringUtils.isBlank) before
building the StringBuilder, replace null checks with blank-aware checks so you
avoid producing "[]", trailing ": " or stray spaces/punctuation, and ensure the
conditional branches around appending the colon, brackets and space use these
normalized booleans (e.g., hasErrorCode, hasErrorMessage) to decide what to
append.
🪄 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: e6d122b8-288e-4fbc-9896-2537490c49ec
📒 Files selected for processing (11)
docs/plans/2026-04-10-typed-exception-hierarchy-design.mdsrc/main/java/ee/bitweb/montonio/sdk/exception/MontonioApiException.javasrc/main/java/ee/bitweb/montonio/sdk/exception/MontonioAuthenticationException.javasrc/main/java/ee/bitweb/montonio/sdk/exception/MontonioException.javasrc/main/java/ee/bitweb/montonio/sdk/exception/MontonioNetworkException.javasrc/main/java/ee/bitweb/montonio/sdk/exception/MontonioValidationException.javasrc/test/java/ee/bitweb/montonio/sdk/exception/MontonioApiExceptionTest.javasrc/test/java/ee/bitweb/montonio/sdk/exception/MontonioAuthenticationExceptionTest.javasrc/test/java/ee/bitweb/montonio/sdk/exception/MontonioExceptionTest.javasrc/test/java/ee/bitweb/montonio/sdk/exception/MontonioNetworkExceptionTest.javasrc/test/java/ee/bitweb/montonio/sdk/exception/MontonioValidationExceptionTest.java
- Fix "hand-written" -> "handwritten" in design doc - Add language hint to fenced code block in design doc - Add cause-aware constructors to MontonioValidationException Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
MontonioExceptionbase class and four specific subtypes:MontonioApiException,MontonioNetworkException,MontonioAuthenticationException, andMontonioValidationExceptiondocs/plans/Design decisions
MontonioExceptionRuntimeException)@Getter; hand-written constructors forsuper()delegationTest plan
./gradlew testpassesCloses #13
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation
Tests