Skip to content

Commit 8ef782a

Browse files
committed
Nit
1 parent 4245f18 commit 8ef782a

File tree

8 files changed

+57
-57
lines changed

8 files changed

+57
-57
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.exceptionless.exceptionlessclient.exceptions;
2+
3+
public class SubmissionClientException extends RuntimeException {
4+
public SubmissionClientException(Throwable cause) {
5+
super(cause);
6+
}
7+
8+
public SubmissionClientException(String message) {
9+
super(message);
10+
}
11+
}

src/main/java/com/exceptionless/exceptionlessclient/exceptions/SubmissionException.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/main/java/com/exceptionless/exceptionlessclient/models/submission/SubmissionResponse.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,34 @@
88
@Value
99
@NonFinal
1010
public class SubmissionResponse {
11-
int statusCode;
12-
String message;
11+
int code;
12+
String body;
1313

1414
public boolean isSuccess() {
15-
return statusCode >= 200 && statusCode <= 299;
15+
return code >= 200 && code <= 299;
1616
}
1717

1818
public boolean isBadRequest() {
19-
return statusCode == 400;
19+
return code == 400;
2020
}
2121

2222
public boolean isServiceUnavailable() {
23-
return statusCode == 503;
23+
return code == 503;
2424
}
2525

2626
public boolean isPaymentRequired() {
27-
return statusCode == 402;
27+
return code == 402;
2828
}
2929

3030
public boolean unableToAuthenticate() {
31-
return statusCode == 401 || statusCode == 403;
31+
return code == 401 || code == 403;
3232
}
3333

3434
public boolean isNotFound() {
35-
return statusCode == 404;
35+
return code == 404;
3636
}
3737

3838
public boolean isRequestEntityTooLarge() {
39-
return statusCode == 413;
39+
return code == 413;
4040
}
4141
}

src/main/java/com/exceptionless/exceptionlessclient/queue/DefaultEventQueue.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.exceptionless.exceptionlessclient.queue;
22

33
import com.exceptionless.exceptionlessclient.configuration.Configuration;
4-
import com.exceptionless.exceptionlessclient.exceptions.SubmissionException;
4+
import com.exceptionless.exceptionlessclient.exceptions.SubmissionClientException;
55
import com.exceptionless.exceptionlessclient.models.Event;
66
import com.exceptionless.exceptionlessclient.models.storage.StorageItem;
77
import com.exceptionless.exceptionlessclient.models.submission.SubmissionResponse;
@@ -136,7 +136,7 @@ public void process() {
136136
SubmissionResponse response = submissionClient.postEvents(events);
137137
processSubmissionResponse(response, storedEvents);
138138
eventPosted(response, events);
139-
} catch (SubmissionException e) {
139+
} catch (SubmissionClientException e) {
140140
LOG.error("Error processing queue", e);
141141
suspendProcessing();
142142
} finally {
@@ -176,7 +176,7 @@ private void processSubmissionResponse(
176176
}
177177

178178
if (response.isNotFound() || response.isBadRequest()) {
179-
LOG.error(String.format("Error while trying to submit data: %s", response.getMessage()));
179+
LOG.error(String.format("Error while trying to submit data: %s", response.getBody()));
180180
suspendProcessing(Duration.ofMinutes(4));
181181
removeEvents(storedEvents);
182182
return;
@@ -195,7 +195,7 @@ private void processSubmissionResponse(
195195
return;
196196
}
197197

198-
LOG.error(String.format("Error submitting events: %s", response.getMessage()));
198+
LOG.error(String.format("Error submitting events: %s", response.getBody()));
199199
suspendProcessing();
200200
}
201201

src/main/java/com/exceptionless/exceptionlessclient/submission/DefaultSubmissionClient.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.exceptionless.exceptionlessclient.submission;
22

33
import com.exceptionless.exceptionlessclient.configuration.Configuration;
4-
import com.exceptionless.exceptionlessclient.exceptions.SubmissionException;
4+
import com.exceptionless.exceptionlessclient.exceptions.SubmissionClientException;
55
import com.exceptionless.exceptionlessclient.models.Event;
66
import com.exceptionless.exceptionlessclient.models.UserDescription;
77
import com.exceptionless.exceptionlessclient.models.submission.SubmissionResponse;
@@ -81,11 +81,11 @@ private SubmissionResponse postSubmission(String url, Object data) {
8181
}
8282

8383
return SubmissionResponse.builder()
84-
.statusCode(response.code())
85-
.message(Utils.addCodeToResponseBodyStr(response))
84+
.code(response.code())
85+
.body(Utils.addCodeToResponseBodyStr(response))
8686
.build();
8787
} catch (Exception e) {
88-
throw new SubmissionException(e);
88+
throw new SubmissionClientException(e);
8989
}
9090
}
9191

@@ -123,7 +123,7 @@ public void sendHeartBeat(String sessionIdOrUserId, boolean closeSession) {
123123
sessionIdOrUserId));
124124
}
125125
} catch (Exception e) {
126-
throw new SubmissionException(e);
126+
throw new SubmissionClientException(e);
127127
}
128128
}
129129
}

src/test/java/com/exceptionless/exceptionlessclient/ExceptionlessClientTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public void itCanSubmitSessionEnd() {
281281

282282
@Test
283283
public void itCanUpdateEmailAndDescription() {
284-
SubmissionResponse expectedResponse = SubmissionResponse.builder().statusCode(200).build();
284+
SubmissionResponse expectedResponse = SubmissionResponse.builder().code(200).build();
285285
doReturn(expectedResponse)
286286
.when(submissionClient)
287287
.postUserDescription(

src/test/java/com/exceptionless/exceptionlessclient/queue/DefaultEventQueueTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.exceptionless.exceptionlessclient.TestFixtures;
44
import com.exceptionless.exceptionlessclient.configuration.Configuration;
5-
import com.exceptionless.exceptionlessclient.exceptions.SubmissionException;
5+
import com.exceptionless.exceptionlessclient.exceptions.SubmissionClientException;
66
import com.exceptionless.exceptionlessclient.models.Event;
77
import com.exceptionless.exceptionlessclient.models.submission.SubmissionResponse;
88
import com.exceptionless.exceptionlessclient.storage.InMemoryStorage;
@@ -63,7 +63,7 @@ public void itCanProcessABatchSuccessfully() {
6363
storage.save(event);
6464

6565
SubmissionResponse response =
66-
SubmissionResponse.builder().message("test-message").statusCode(200).build();
66+
SubmissionResponse.builder().body("test-message").code(200).build();
6767
doReturn(response).when(submissionClient).postEvents(List.of(event));
6868

6969
queue.onEventsPosted(testHandler);
@@ -80,7 +80,7 @@ public void itShouldNotProcessIfCurrentlyProcessingEvents()
8080
storage.save(event);
8181

8282
SubmissionResponse response =
83-
SubmissionResponse.builder().message("test-message").statusCode(200).build();
83+
SubmissionResponse.builder().body("test-message").code(200).build();
8484
doAnswer(
8585
invocationOnMock -> {
8686
Thread.sleep(1000);
@@ -111,7 +111,7 @@ public void itShouldNotPostEmptyEvents() {
111111
public void itShouldSuspendProcessingOnClientException() {
112112
storage.save(event);
113113

114-
doThrow(new SubmissionException("test")).when(submissionClient).postEvents(List.of(event));
114+
doThrow(new SubmissionClientException("test")).when(submissionClient).postEvents(List.of(event));
115115

116116
queue.onEventsPosted(testHandler);
117117
queue.process();
@@ -126,7 +126,7 @@ public void itShouldSuspendProcessingIfServiceIsUnavailable() {
126126
storage.save(event);
127127

128128
SubmissionResponse response =
129-
SubmissionResponse.builder().message("test-message").statusCode(503).build();
129+
SubmissionResponse.builder().body("test-message").code(503).build();
130130
doReturn(response).when(submissionClient).postEvents(List.of(event));
131131

132132
queue.onEventsPosted(testHandler);
@@ -142,7 +142,7 @@ public void itShouldSuspendAndDiscardProcessingAndClearQueueIfNoPayment() {
142142
storage.save(event);
143143

144144
SubmissionResponse response =
145-
SubmissionResponse.builder().message("test-message").statusCode(402).build();
145+
SubmissionResponse.builder().body("test-message").code(402).build();
146146
doReturn(response).when(submissionClient).postEvents(List.of(event));
147147

148148
queue.onEventsPosted(testHandler);
@@ -162,7 +162,7 @@ public void itShouldSuspendProcessingAndClearQueueIfUnableToAuthenticate() {
162162
storage.save(event);
163163

164164
SubmissionResponse response =
165-
SubmissionResponse.builder().message("test-message").statusCode(401).build();
165+
SubmissionResponse.builder().body("test-message").code(401).build();
166166
doReturn(response).when(submissionClient).postEvents(List.of(event));
167167

168168
queue.onEventsPosted(testHandler);
@@ -178,7 +178,7 @@ public void itShouldSuspendProcessingAndClearQueueForNotFoundResponse() {
178178
storage.save(event);
179179

180180
SubmissionResponse response =
181-
SubmissionResponse.builder().message("test-message").statusCode(404).build();
181+
SubmissionResponse.builder().body("test-message").code(404).build();
182182
doReturn(response).when(submissionClient).postEvents(List.of(event));
183183

184184
queue.onEventsPosted(testHandler);
@@ -194,7 +194,7 @@ public void itShouldSuspendProcessingAndClearQueueForBadRequest() {
194194
storage.save(event);
195195

196196
SubmissionResponse response =
197-
SubmissionResponse.builder().message("test-message").statusCode(400).build();
197+
SubmissionResponse.builder().body("test-message").code(400).build();
198198
doReturn(response).when(submissionClient).postEvents(List.of(event));
199199

200200
queue.onEventsPosted(testHandler);
@@ -210,7 +210,7 @@ public void itShouldSuspendProcessingByDefault() {
210210
storage.save(event);
211211

212212
SubmissionResponse response =
213-
SubmissionResponse.builder().message("test-message").statusCode(-1).build();
213+
SubmissionResponse.builder().body("test-message").code(-1).build();
214214
doReturn(response).when(submissionClient).postEvents(List.of(event));
215215

216216
queue.onEventsPosted(testHandler);
@@ -238,7 +238,7 @@ public void itShouldReduceSubmissionBatchSizeIfRequestEntitiesAreTooLarge() {
238238
}
239239

240240
SubmissionResponse response =
241-
SubmissionResponse.builder().message("test-message").statusCode(413).build();
241+
SubmissionResponse.builder().body("test-message").code(413).build();
242242
doReturn(response).when(submissionClient).postEvents(anyList());
243243

244244
queue.onEventsPosted(testHandler);
@@ -264,7 +264,7 @@ public void itShouldDiscardEventsIfItCantReduceSubmissionSizeAndRequestEntitiesA
264264
}
265265

266266
SubmissionResponse response =
267-
SubmissionResponse.builder().message("test-message").statusCode(413).build();
267+
SubmissionResponse.builder().body("test-message").code(413).build();
268268
doReturn(response).when(submissionClient).postEvents(anyList());
269269

270270
queue.onEventsPosted(testHandler);
@@ -290,12 +290,12 @@ public void itShouldResetSubmissionBatchSizeOnNextSuccessfulResponse() {
290290
storage.save(event);
291291
}
292292

293-
doReturn(SubmissionResponse.builder().message("test-message").statusCode(413).build())
293+
doReturn(SubmissionResponse.builder().body("test-message").code(413).build())
294294
.when(submissionClient)
295295
.postEvents(anyList());
296296
queue.process();
297297

298-
doReturn(SubmissionResponse.builder().message("test-message").statusCode(200).build())
298+
doReturn(SubmissionResponse.builder().body("test-message").code(200).build())
299299
.when(submissionClient)
300300
.postEvents(anyList());
301301
queue.process();
@@ -314,7 +314,7 @@ public void itShouldResetSubmissionBatchSizeOnNextSuccessfulResponse() {
314314
public void itShouldProcessEventsUsingTimer() throws InterruptedException {
315315
storage.save(event);
316316
SubmissionResponse response =
317-
SubmissionResponse.builder().message("test-message").statusCode(200).build();
317+
SubmissionResponse.builder().body("test-message").code(200).build();
318318
doReturn(response).when(submissionClient).postEvents(List.of(event));
319319

320320
Configuration configuration =

src/test/java/com/exceptionless/exceptionlessclient/submission/DefaultSubmissionClientTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.exceptionless.exceptionlessclient.TestFixtures;
44
import com.exceptionless.exceptionlessclient.configuration.Configuration;
5-
import com.exceptionless.exceptionlessclient.exceptions.SubmissionException;
5+
import com.exceptionless.exceptionlessclient.exceptions.SubmissionClientException;
66
import com.exceptionless.exceptionlessclient.models.Event;
77
import com.exceptionless.exceptionlessclient.models.UserDescription;
88
import com.exceptionless.exceptionlessclient.models.submission.SubmissionResponse;
@@ -72,8 +72,8 @@ public void itCanPostEventsSuccessfully() throws IOException {
7272
SubmissionResponse submissionResponse =
7373
submissionClient.postEvents(List.of(Event.builder().build()));
7474

75-
assertThat(submissionResponse.getMessage()).isEqualTo("Code: 200, Body: test-body");
76-
assertThat(submissionResponse.getStatusCode()).isEqualTo(200);
75+
assertThat(submissionResponse.getBody()).isEqualTo("Code: 200, Body: test-body");
76+
assertThat(submissionResponse.getCode()).isEqualTo(200);
7777
verify(settingsManager, times(1)).checkVersion(3);
7878
}
7979

@@ -85,8 +85,8 @@ public void itCanPostEventsSuccessfullyWhenNoSettingHeaderIsReturned() throws IO
8585
SubmissionResponse submissionResponse =
8686
submissionClient.postEvents(List.of(Event.builder().build()));
8787

88-
assertThat(submissionResponse.getMessage()).isEqualTo("Code: 200, Body: test-body");
89-
assertThat(submissionResponse.getStatusCode()).isEqualTo(200);
88+
assertThat(submissionResponse.getBody()).isEqualTo("Code: 200, Body: test-body");
89+
assertThat(submissionResponse.getCode()).isEqualTo(200);
9090
verifyZeroInteractions(settingsManager);
9191
}
9292

@@ -95,7 +95,7 @@ public void itCanThrowAllExceptionsAsSubmissionExceptionWhilePostingEvents() {
9595
doThrow(new RuntimeException("test")).when(httpClient).newCall(any());
9696

9797
assertThatThrownBy(() -> submissionClient.postEvents(List.of(Event.builder().build())))
98-
.isInstanceOf(SubmissionException.class)
98+
.isInstanceOf(SubmissionClientException.class)
9999
.hasMessage("java.lang.RuntimeException: test");
100100
}
101101

@@ -120,8 +120,8 @@ public void itCanPostUserDescriptionSuccessfully() throws IOException {
120120
submissionClient.postUserDescription(
121121
"test-reference-id", UserDescription.builder().build());
122122

123-
assertThat(submissionResponse.getMessage()).isEqualTo("Code: 200, Body: test-body");
124-
assertThat(submissionResponse.getStatusCode()).isEqualTo(200);
123+
assertThat(submissionResponse.getBody()).isEqualTo("Code: 200, Body: test-body");
124+
assertThat(submissionResponse.getCode()).isEqualTo(200);
125125
verify(settingsManager, times(1)).checkVersion(3);
126126
}
127127

@@ -135,8 +135,8 @@ public void itCanPostUserDescriptionSuccessfullyWhenNoSettingHeaderIsReturned()
135135
submissionClient.postUserDescription(
136136
"test-reference-id", UserDescription.builder().build());
137137

138-
assertThat(submissionResponse.getMessage()).isEqualTo("Code: 200, Body: test-body");
139-
assertThat(submissionResponse.getStatusCode()).isEqualTo(200);
138+
assertThat(submissionResponse.getBody()).isEqualTo("Code: 200, Body: test-body");
139+
assertThat(submissionResponse.getCode()).isEqualTo(200);
140140
verifyZeroInteractions(settingsManager);
141141
}
142142

@@ -148,7 +148,7 @@ public void itCanThrowAllExceptionsAsSubmissionExceptionWhilePostingUserDescript
148148
() ->
149149
submissionClient.postUserDescription(
150150
"test-reference-id", UserDescription.builder().build()))
151-
.isInstanceOf(SubmissionException.class)
151+
.isInstanceOf(SubmissionClientException.class)
152152
.hasMessage("java.lang.RuntimeException: test");
153153
}
154154

@@ -177,7 +177,7 @@ public void itCanThrowAllExceptionsAsSubmissionExceptionWhileSendingHeartbeat()
177177
doThrow(new RuntimeException("test")).when(httpClient).newCall(any());
178178

179179
assertThatThrownBy(() -> submissionClient.sendHeartBeat("test-user-id", true))
180-
.isInstanceOf(SubmissionException.class)
180+
.isInstanceOf(SubmissionClientException.class)
181181
.hasMessage("java.lang.RuntimeException: test");
182182
}
183183
}

0 commit comments

Comments
 (0)