Repository: olingo-odata4 Updated Branches: refs/heads/master 272719d59 -> a16a16841
[OLINGO-1102] Missing Detail error message for ODataServerErrorException Signed-off-by: Christian Amend <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/a16a1684 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/a16a1684 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/a16a1684 Branch: refs/heads/master Commit: a16a16841b03fe27b1fb0dab20a0d0029a6de335 Parents: 272719d Author: i050510 <[email protected]> Authored: Wed Apr 26 11:13:13 2017 +0530 Committer: Christian Amend <[email protected]> Committed: Wed Apr 26 16:28:18 2017 +0200 ---------------------------------------------------------------------- .../header/ODataErrorResponseChecker.java | 3 +- .../apache/olingo/client/core/ErrorTest.java | 48 +++++++++++++++++++- .../org/apache/olingo/client/core/500error.json | 10 ++++ .../apache/olingo/client/core/500error1.json | 6 +++ 4 files changed, 64 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a16a1684/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java index d83b8fb..274da3a 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java @@ -69,7 +69,8 @@ public final class ODataErrorResponseChecker { statusLine.getReasonPhrase()); } - if (statusLine.getStatusCode() >= 500) { + if (statusLine.getStatusCode() >= 500 && (error.getDetails() == null || error.getDetails().size() == 0) && + (error.getInnerError() == null || error.getInnerError().size() == 0)) { result = new ODataServerErrorException(statusLine); } else { result = new ODataClientErrorException(statusLine, error); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a16a1684/lib/client-core/src/test/java/org/apache/olingo/client/core/ErrorTest.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/ErrorTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/ErrorTest.java index b930464..4446e92 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/ErrorTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/ErrorTest.java @@ -18,14 +18,25 @@ */ package org.apache.olingo.client.core; -import java.util.Map; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import java.io.InputStream; +import java.util.Map; + +import org.apache.http.StatusLine; +import org.apache.olingo.client.api.ODataClient; +import org.apache.olingo.client.api.communication.ODataClientErrorException; +import org.apache.olingo.client.api.communication.ODataServerErrorException; import org.apache.olingo.client.api.serialization.ODataDeserializerException; +import org.apache.olingo.client.core.communication.header.ODataErrorResponseChecker; import org.apache.olingo.commons.api.ex.ODataError; import org.apache.olingo.commons.api.ex.ODataErrorDetail; import org.apache.olingo.commons.api.format.ContentType; -import static org.junit.Assert.assertEquals; import org.junit.Test; public class ErrorTest extends AbstractTest { @@ -69,4 +80,37 @@ public class ErrorTest extends AbstractTest { simple(ContentType.APPLICATION_ATOM_XML); } + @Test + public void test1OLINGO1102() throws Exception { + ODataClient odataClient = ODataClientFactory.getClient(); + InputStream entity = getClass().getResourceAsStream("500error." + getSuffix(ContentType.JSON)); + StatusLine statusLine = mock(StatusLine.class); + when(statusLine.getStatusCode()).thenReturn(500); + when(statusLine.toString()).thenReturn("Internal Server Error"); + + ODataClientErrorException exp = (ODataClientErrorException) ODataErrorResponseChecker. + checkResponse(odataClient, statusLine, entity, "Json"); + assertTrue(exp.getMessage().contains("(500) Internal Server Error")); + ODataError error = exp.getODataError(); + assertEquals("Internal Server Error", error.getMessage()); + assertEquals(500, Integer.parseInt(error.getCode())); + assertEquals(2, error.getInnerError().size()); + assertEquals("\"Method does not support entities of specific type\"", error.getInnerError().get("message")); + assertEquals("\"FaultException\"", error.getInnerError().get("type")); + assertNull(error.getDetails()); + + } + + @Test + public void test2OLINGO1102() throws Exception { + ODataClient odataClient = ODataClientFactory.getClient(); + InputStream entity = getClass().getResourceAsStream("500error1." + getSuffix(ContentType.JSON)); + StatusLine statusLine = mock(StatusLine.class); + when(statusLine.getStatusCode()).thenReturn(500); + when(statusLine.toString()).thenReturn("Internal Server Error"); + + ODataServerErrorException exp = (ODataServerErrorException) ODataErrorResponseChecker. + checkResponse(odataClient, statusLine, entity, "Json"); + assertEquals("Internal Server Error", exp.getMessage()); + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a16a1684/lib/client-core/src/test/resources/org/apache/olingo/client/core/500error.json ---------------------------------------------------------------------- diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/500error.json b/lib/client-core/src/test/resources/org/apache/olingo/client/core/500error.json new file mode 100644 index 0000000..0c7a9e8 --- /dev/null +++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/500error.json @@ -0,0 +1,10 @@ +{ + "error": { + "code": "500", + "message": "Internal Server Error", + "innererror": { + "type": "FaultException", + "message": "Method does not support entities of specific type" + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a16a1684/lib/client-core/src/test/resources/org/apache/olingo/client/core/500error1.json ---------------------------------------------------------------------- diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/500error1.json b/lib/client-core/src/test/resources/org/apache/olingo/client/core/500error1.json new file mode 100644 index 0000000..d7c7f3a --- /dev/null +++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/500error1.json @@ -0,0 +1,6 @@ +{ + "error": { + "code": "500", + "message": "Internal Server Error" + } +} \ No newline at end of file
