Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/io/getstream/exceptions/StreamException.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public static StreamException build(Response httpResponse) {
if (parsed == null) {
String msg =
parseCause != null
? "failed to parse error response"
? String.format(
"failed to parse error response: unexpected server response code %d", status)
: String.format("Unexpected server response code %d", status);
if (status == 429) {
return new StreamRateLimitException(
Expand Down
18 changes: 15 additions & 3 deletions src/test/java/io/getstream/ModerationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public class ModerationTest {
static String testUserId;
static String testUserId2;
static String testModeratorId;
// The ban tests need their own target. A global ban on testUserId survives for
// the rest of the class, and a banned user cannot add an activity, so the
// activity tests failed whenever they ran after the ban.
static String bannedUserId;
static String testFeedId;
static String testActivityId;

Expand All @@ -34,6 +38,7 @@ static void setup() throws Exception {
testUserId = "test-user-" + RandomStringUtils.randomAlphanumeric(8);
testUserId2 = "test-user-2-" + RandomStringUtils.randomAlphanumeric(8);
testModeratorId = "moderator-" + RandomStringUtils.randomAlphanumeric(8);
bannedUserId = "banned-user-" + RandomStringUtils.randomAlphanumeric(8);

Map<String, UserRequest> usersMap = new HashMap<>();
usersMap.put(
Expand All @@ -53,6 +58,13 @@ static void setup() throws Exception {
.name("Moderator " + testModeratorId)
.role("admin")
.build());
usersMap.put(
bannedUserId,
UserRequest.builder()
.id(bannedUserId)
.name("Banned User " + bannedUserId)
.role("user")
.build());

UpdateUsersRequest updateUsersRequest = UpdateUsersRequest.builder().users(usersMap).build();
client.updateUsers(updateUsersRequest).execute();
Expand All @@ -71,7 +83,7 @@ void testBanWithReason() throws Exception {
// snippet-start: BanWithReason
BanRequest request =
BanRequest.builder()
.targetUserID(testUserId)
.targetUserID(bannedUserId)
.reason("spam")
.timeout(60) // 60 minutes
.bannedByID(testModeratorId)
Expand Down Expand Up @@ -206,15 +218,15 @@ void testUnbanUser() throws Exception {
// First ban the user
BanRequest banRequest =
BanRequest.builder()
.targetUserID(testUserId)
.targetUserID(bannedUserId)
.reason("test")
.bannedByID(testModeratorId)
.build();
moderation.ban(banRequest).execute();

// snippet-start: UnbanUser
UnbanRequest request =
UnbanRequest.builder().TargetUserID(testUserId).unbannedByID(testModeratorId).build();
UnbanRequest.builder().TargetUserID(bannedUserId).unbannedByID(testModeratorId).build();

UnbanResponse response = moderation.unban(request).execute().getData();
// snippet-end: UnbanUser
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/io/getstream/StreamErrorHandlingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ void apiUnparseableBody_setsRawBodyAndZeroCode() {
StreamApiException e = assertThrows(StreamApiException.class, () -> request().execute());
assertEquals(502, e.getStatusCode(), "status code preserved when body is unparseable");
assertEquals(0, e.getCode(), "unparseable body → code 0");
assertEquals("failed to parse error response", e.getMessage());
assertEquals(
"failed to parse error response: unexpected server response code 502", e.getMessage());
assertEquals("<html>bad gateway</html>", e.getRawResponseBody());
assertNotNull(e.getCause(), "parse error preserved on cause chain");
}
Expand Down
Loading