Skip to content

Fix error message to fallback to title when detail is missing#36

Merged
Fivell merged 5 commits intomainfrom
fix/error-message-title-fallback
Mar 11, 2026
Merged

Fix error message to fallback to title when detail is missing#36
Fivell merged 5 commits intomainfrom
fix/error-message-title-fallback

Conversation

@Fivell
Copy link
Member

@Fivell Fivell commented Mar 10, 2026

Summary

  • Added getMessage() to ApiError that returns detail if present, otherwise title
  • Updated buildMessage() to use it

Test plan

  • 6 tests covering detail, title-only, and no-errors scenarios
  • All tests pass

@Fivell Fivell requested a review from Copilot March 10, 2026 22:37
@Fivell Fivell force-pushed the fix/error-message-title-fallback branch from 702c1a9 to 138daa7 Compare March 10, 2026 22:39
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 return detail when present, otherwise title
  • Updated DidwwApiException#buildMessage() to use ApiError#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.

Comment on lines +6 to +7
import java.util.List;

Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
import java.util.List;

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines 34 to 38
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());
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +73 to +76
public String getMessage() {
if (detail != null) return detail;
if (title != null) return title;
return "Unknown error";
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +69 to +77
/**
* 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";
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@Fivell Fivell force-pushed the fix/error-message-title-fallback branch from 349c54d to 39f9aa9 Compare March 11, 2026 16:21
@Fivell Fivell requested a review from Copilot March 11, 2026 16:31
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +71 to +84
@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");
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Fivell added 4 commits March 11, 2026 22:19
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.
@Fivell Fivell force-pushed the fix/error-message-title-fallback branch from 39f9aa9 to 89aca10 Compare March 11, 2026 21:19
@Fivell Fivell requested a review from Copilot March 11, 2026 21:19
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +77 to +80
/**
* Returns {@code detail} if present, otherwise falls back to {@code title},
* or {@code "Unknown error"} when both are absent.
*/
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@sonarqubecloud
Copy link

@Fivell Fivell merged commit 40d8cf5 into main Mar 11, 2026
5 checks passed
@Fivell Fivell deleted the fix/error-message-title-fallback branch March 11, 2026 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants