File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
main/java/com/rollbar/notifier/sender/json
test/java/com/rollbar/notifier/sender/json Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -71,7 +71,12 @@ public String toJson(Payload payload) {
7171 @ Override
7272 public Result resultFrom (String response ) {
7373 Matcher codeMatcher = CODE_PATTERN .matcher (response );
74- codeMatcher .find ();
74+ if (!codeMatcher .find ()) {
75+ return new Result .Builder ()
76+ .code (1 )
77+ .body (response )
78+ .build ();
79+ }
7580 String codeStr = codeMatcher .group (1 );
7681 int code ;
7782 try {
Original file line number Diff line number Diff line change @@ -12,11 +12,16 @@ public class JsonSerializerImplTest {
1212
1313 static final String ERROR_MESSAGE = "This is the error message" ;
1414
15+ static final String UNEXPECTED_ERROR_MESSAGE = "Nobody expects the Spanish inquisition" ;
16+
1517 static final String UUID = java .util .UUID .randomUUID ().toString ();
1618
1719 static final String ERROR_RESPONSE = format ("{\" err\" : 1, {\" message\" : \" %s\" }}" ,
1820 ERROR_MESSAGE );
1921
22+ static final String UNEXPECTED_ERROR_RESPONSE = format ("<html><body>%s</body></html>" ,
23+ UNEXPECTED_ERROR_MESSAGE );
24+
2025 static final String SUCCESS_RESPONSE = format ("{\" err\" : 0, {\" uuid\" : \" %s\" }}" ,
2126 UUID );
2227
@@ -32,6 +37,18 @@ public void shouldDeserializeErrorResponse() {
3237 assertThat (sut .resultFrom (ERROR_RESPONSE ), is (result ));
3338 }
3439
40+ @ Test
41+ public void shouldDeserializeUnexpectedErrorResponse () {
42+ Result result = new Result .Builder ()
43+ .code (1 )
44+ .body (UNEXPECTED_ERROR_RESPONSE )
45+ .build ();
46+
47+ JsonSerializerImpl sut = new JsonSerializerImpl ();
48+
49+ assertThat (sut .resultFrom (UNEXPECTED_ERROR_RESPONSE ), is (result ));
50+ }
51+
3552 @ Test
3653 public void shouldDeserializeSuccessResponse () {
3754 Result result = new Result .Builder ()
You can’t perform that action at this time.
0 commit comments