Fix error message to fallback to title when detail is missing#36
Fix error message to fallback to title when detail is missing#36
Conversation
702c1a9 to
138daa7
Compare
There was a problem hiding this comment.
Pull request overview
This PR improves DIDWW API exception messaging by introducing a fallback to the error title when detail is absent, and adds tests to cover the new behavior.
Changes:
- Added
ApiError#getMessage()to returndetailwhen present, otherwisetitle - Updated
DidwwApiException#buildMessage()to useApiError#getMessage() - Added unit/integration-style tests covering detail, title-only fallback, and missing errors array scenarios
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/main/java/com/didww/sdk/exception/DidwwApiException.java |
Uses a new ApiError#getMessage() fallback to build clearer exception messages |
src/test/java/com/didww/sdk/exception/DidwwApiExceptionTest.java |
Adds coverage for detail vs title fallback and no-errors responses |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import java.util.List; | ||
|
|
There was a problem hiding this comment.
Unused import java.util.List is added but not referenced anywhere in this test class; please remove it to keep the test sources clean and avoid compiler warnings.
| import java.util.List; |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| sb.append(": "); | ||
| for (int i = 0; i < errors.size(); i++) { | ||
| if (i > 0) sb.append("; "); | ||
| sb.append(errors.get(i).getDetail()); | ||
| sb.append(errors.get(i).getMessage()); | ||
| } |
There was a problem hiding this comment.
ApiError#getMessage() can return null (e.g., when both detail and title are missing), and StringBuilder.append(null) will append the literal string "null" into the exception message. Consider skipping null/blank error messages in buildMessage() or providing a fallback (e.g., status/code or a generic placeholder) to avoid confusing exception messages.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public String getMessage() { | ||
| if (detail != null) return detail; | ||
| if (title != null) return title; | ||
| return "Unknown error"; |
There was a problem hiding this comment.
ApiError#getMessage() introduces a new Jackson bean property named message. Since the SDK ObjectMapper disables FAIL_ON_UNKNOWN_PROPERTIES, an errors[].message field would previously be ignored but may now fail deserialization because this property has no setter/field. Consider marking this helper with @JsonIgnore (as done for other helper getters) or @JsonProperty(access = READ_ONLY) so it won’t participate in JSON mapping.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /** | ||
| * Returns {@code detail} if present, otherwise falls back to {@code title}, | ||
| * or {@code "Unknown error"} when both are absent. | ||
| */ | ||
| public String getMessage() { | ||
| if (detail != null) return detail; | ||
| if (title != null) return title; | ||
| return "Unknown error"; | ||
| } |
There was a problem hiding this comment.
ApiError#getMessage() is a derived/computed value; leaving it as a standard getter will make Jackson treat it as a real message property during serialization (and potentially during deserialization depending on mapper settings). In this codebase, computed getters (e.g., getType() implementations) are annotated with @JsonIgnore; consider doing the same here to avoid emitting a non-JSON:API field while still allowing callers to use the helper method in Java.
349c54d to
39f9aa9
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @Test | ||
| void testApiErrorGetMessageReturnsDetailOverTitle() { | ||
| DidwwApiException.ApiError error = new DidwwApiException.ApiError(); | ||
| error.setTitle("Some Title"); | ||
| error.setDetail("Some Detail"); | ||
| assertThat(error.getMessage()).isEqualTo("Some Detail"); | ||
| } | ||
|
|
||
| @Test | ||
| void testApiErrorGetMessageFallsBackToTitle() { | ||
| DidwwApiException.ApiError error = new DidwwApiException.ApiError(); | ||
| error.setTitle("Some Title"); | ||
| assertThat(error.getMessage()).isEqualTo("Some Title"); | ||
| } |
There was a problem hiding this comment.
The new tests cover null/missing detail but don’t cover the case where detail is present but blank/whitespace, which currently prevents fallback to title. Adding a test for blank detail (and optionally blank title) would lock in the intended fallback behavior and catch regressions.
Prevent StringBuilder.append(null) from adding literal "null" string to exception messages by returning "Unknown error" as a fallback in ApiError#getMessage() when both detail and title are absent.
39f9aa9 to
89aca10
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /** | ||
| * Returns {@code detail} if present, otherwise falls back to {@code title}, | ||
| * or {@code "Unknown error"} when both are absent. | ||
| */ |
There was a problem hiding this comment.
PR description says getMessage() returns detail if present, otherwise title, but the implementation (and tests) also add a third fallback of "Unknown error" when both are absent. Please update the PR description to reflect this behavior (or drop the extra fallback if it’s not intended).
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|



Summary
getMessage()to ApiError that returns detail if present, otherwise titlebuildMessage()to use itTest plan