Skip to content

Commit 6c519b2

Browse files
authored
Merge pull request #73 from LeonisX/master
Avoid StackOverflowError in XeroExceptionHandler
2 parents 8677946 + 6e39dae commit 6c519b2

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/main/java/com/xero/api/exception/XeroExceptionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public XeroApiException handleBadRequest(HttpResponseException httpResponseExcep
8080
return convertException(httpResponseException);
8181
}
8282
} else {
83-
return convertException(httpResponseException);
83+
return newApiException(httpResponseException);
8484
}
8585
}
8686

src/test/java/com/xero/api/exception/XeroExceptionHandlerTest.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
import org.mockito.Mock;
1414
import org.mockito.junit.MockitoJUnitRunner;
1515

16-
import static org.junit.Assert.assertFalse;
17-
import static org.junit.Assert.assertNotNull;
18-
import static org.junit.Assert.assertTrue;
16+
import static org.junit.Assert.*;
1917
import static org.mockito.Mockito.when;
2018

2119
@RunWith(MockitoJUnitRunner.class)
@@ -67,6 +65,17 @@ public void handleOAuthErrorRequest() throws Exception {
6765
assertNotNull(xeroApiException.getMessage());
6866
}
6967

68+
@Test
69+
public void handleOtherErrorRequest() throws Exception {
70+
when(httpResponseException.getContent()).thenReturn("dummy");
71+
when(httpResponseException.getStatusCode()).thenReturn(400);
72+
XeroApiException xeroApiException = xeroExceptionHandler.handleBadRequest(httpResponseException);
73+
assertNotNull(xeroApiException);
74+
assertNotNull(xeroApiException.getMessages());
75+
assertNotNull(xeroApiException.getMessage());
76+
assertEquals(xeroApiException.getResponseCode(), 400);
77+
}
78+
7079
/**
7180
* sample oauth exception
7281
* @return oauth exception

0 commit comments

Comments
 (0)