From 6e39dae8e041475e68548572a0a92f20b54cb5ca Mon Sep 17 00:00:00 2001 From: Leonis Date: Fri, 2 Mar 2018 15:21:03 +0200 Subject: [PATCH] Avoid StackOverflowError in XeroExceptionHandler --- .../xero/api/exception/XeroExceptionHandler.java | 2 +- .../api/exception/XeroExceptionHandlerTest.java | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/xero/api/exception/XeroExceptionHandler.java b/src/main/java/com/xero/api/exception/XeroExceptionHandler.java index e39c2e0c..259f3ca6 100644 --- a/src/main/java/com/xero/api/exception/XeroExceptionHandler.java +++ b/src/main/java/com/xero/api/exception/XeroExceptionHandler.java @@ -77,7 +77,7 @@ public XeroApiException handleBadRequest(HttpResponseException httpResponseExcep return convertException(httpResponseException); } } else { - return convertException(httpResponseException); + return newApiException(httpResponseException); } } diff --git a/src/test/java/com/xero/api/exception/XeroExceptionHandlerTest.java b/src/test/java/com/xero/api/exception/XeroExceptionHandlerTest.java index dbe85b68..ef1bc0b3 100644 --- a/src/test/java/com/xero/api/exception/XeroExceptionHandlerTest.java +++ b/src/test/java/com/xero/api/exception/XeroExceptionHandlerTest.java @@ -13,9 +13,7 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) @@ -67,6 +65,17 @@ public void handleOAuthErrorRequest() throws Exception { assertNotNull(xeroApiException.getMessage()); } + @Test + public void handleOtherErrorRequest() throws Exception { + when(httpResponseException.getContent()).thenReturn("dummy"); + when(httpResponseException.getStatusCode()).thenReturn(400); + XeroApiException xeroApiException = xeroExceptionHandler.handleBadRequest(httpResponseException); + assertNotNull(xeroApiException); + assertNotNull(xeroApiException.getMessages()); + assertNotNull(xeroApiException.getMessage()); + assertEquals(xeroApiException.getResponseCode(), 400); + } + /** * sample oauth exception * @return oauth exception