fix: issues found in the invitations live check

- guest list failed when no guest was linked yet (Map.of().get(null))
- counter errors arrive as ProblemDetail: read the reason code from detail;
  drop the counter error advice the core handler always overrode
- emails published with a null sender failed the NOT NULL column

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-01 17:27:22 +08:00
1 parent aed9473aba
commit fbbc5d0980
10 files changed
+115 -87

No files matched your search

@@ -278,7 +278,9 @@ public class AdminEventService {
private static String counterField(HttpClientErrorException e, String field, String fallback) {
try {
String v = new ObjectMapper().readTree(e.getResponseBodyAsString()).path(field).asText();
// The counter's core error handler sends a ProblemDetail whose "detail" is the reason code.
com.fasterxml.jackson.databind.JsonNode body = new ObjectMapper().readTree(e.getResponseBodyAsString());
String v = body.path(field).asText("code".equals(field) ? body.path("detail").asText() : "");
return v.isEmpty() ? fallback : v;
} catch (Exception ex) {
return fallback;
@@ -184,7 +184,9 @@ public class PublicInviteService {
private static String counterCode(HttpClientErrorException e) {
try {
String v = new ObjectMapper().readTree(e.getResponseBodyAsString()).path("code").asText();
// The counter's core error handler sends a ProblemDetail whose "detail" is the reason code.
com.fasterxml.jackson.databind.JsonNode body = new ObjectMapper().readTree(e.getResponseBodyAsString());
String v = body.path("code").asText(body.path("detail").asText());
return v.isEmpty() ? "CONFLICT" : v;
} catch (Exception ex) {
return "CONFLICT";
@@ -146,6 +146,16 @@ class AdminEventServiceCapacityTest {
});
}
@Test
void update_capBelowGuests_fromTheCountersProblemDetailBody() {
grantGuestsModuleToRole(3L);
when(rest.postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), any()))
.thenThrow(HttpClientErrorException.create(HttpStatus.CONFLICT, "Conflict", null,
"{\"type\":\"about:blank\",\"title\":\"Conflict\",\"status\":409,\"detail\":\"CAP_BELOW_GUESTS\"}".getBytes(), null));
assertThatThrownBy(() -> service.update(String.valueOf(UUID), req(800, 1)))
.isInstanceOfSatisfying(CodedResponseStatusException.class, e -> assertThat(e.getCode()).isEqualTo("CAP_BELOW_GUESTS"));
}
@Test
void update_failedModuleLookup_failsClosedAndKeepsLimits() {
when(rest.getForEntity(eq(MODULES), any(ParameterizedTypeReference.class), eq("BO"))).thenThrow(new IllegalStateException("down"));
@@ -301,6 +301,18 @@ class PublicInviteServiceTest {
});
}
@Test
void inviteRegister_eventFull_fromTheCountersProblemDetailBody() {
// The counter's core handler renders ResponseStatusException as a ProblemDetail: the reason is in "detail".
when(rest.postForEntity(eq(GUEST_REGISTER), any(ParameterizedTypeReference.class), any())).thenThrow(
HttpClientErrorException.create(HttpStatus.CONFLICT, "c", null,
"{\"type\":\"about:blank\",\"title\":\"Conflict\",\"status\":409,\"detail\":\"EVENT_FULL\"}".getBytes(), null));
assertThatThrownBy(() -> service.inviteRegister(GT, ok())).isInstanceOfSatisfying(CodedResponseStatusException.class, e -> {
assertThat(e.getReason()).isEqualTo("This event is full");
assertThat(e.getBody().getProperties()).containsEntry("code", "EVENT_FULL");
});
}
// --- invite check-in ---
@Test