[OLINGO-1190]To get the exact exception reason from odata service, instead of getting a generic message.
This commit is contained in:
parent
48263a8ce3
commit
ac02329d1f
|
@ -19,6 +19,7 @@
|
|||
package org.apache.olingo.client.core.communication.header;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.olingo.client.api.ODataClient;
|
||||
|
@ -57,6 +58,16 @@ public final class ODataErrorResponseChecker {
|
|||
ODataError error;
|
||||
try {
|
||||
error = odataClient.getReader().readError(entity, contentType);
|
||||
if (error != null) {
|
||||
Map<String, String> innerError = error.getInnerError();
|
||||
if (innerError != null) {
|
||||
if (innerError.get("internalexception") != null) {
|
||||
error.setMessage(error.getMessage() + innerError.get("internalexception"));
|
||||
} else {
|
||||
error.setMessage(error.getMessage() + innerError.get("message"));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final RuntimeException e) {
|
||||
LOG.warn("Error deserializing error response", e);
|
||||
error = getGenericError(
|
||||
|
|
|
@ -92,7 +92,7 @@ public class ErrorTest extends AbstractTest {
|
|||
checkResponse(odataClient, statusLine, entity, "Json");
|
||||
assertTrue(exp.getMessage().contains("(500) Internal Server Error"));
|
||||
ODataError error = exp.getODataError();
|
||||
assertEquals("Internal Server Error", error.getMessage());
|
||||
assertTrue(error.getMessage().startsWith("Internal Server Error"));
|
||||
assertEquals(500, Integer.parseInt(error.getCode()));
|
||||
assertEquals(2, error.getInnerError().size());
|
||||
assertEquals("\"Method does not support entities of specific type\"", error.getInnerError().get("message"));
|
||||
|
@ -111,6 +111,6 @@ public class ErrorTest extends AbstractTest {
|
|||
|
||||
ODataServerErrorException exp = (ODataServerErrorException) ODataErrorResponseChecker.
|
||||
checkResponse(odataClient, statusLine, entity, "Json");
|
||||
assertEquals("Internal Server Error", exp.getMessage());
|
||||
assertTrue(exp.getMessage().startsWith("Internal Server Error"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue