You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2022/08/13 10:34:43 UTC

[olingo-odata4] 01/01: [OLINGO-1574] Better error messages for client

This is an automated email from the ASF dual-hosted git repository.

mibo pushed a commit to branch OLINGO-1574
in repository https://gitbox.apache.org/repos/asf/olingo-odata4.git

commit 797f16a3d10321d5cb1faf090b20d9f46f464bc1
Author: mibo <mi...@apache.org>
AuthorDate: Sat Aug 13 12:34:15 2022 +0200

    [OLINGO-1574] Better error messages for client
---
 .../proxy/commons/TransactionalPersistenceManagerImpl.java |  2 +-
 .../api/communication/ODataClientErrorException.java       | 14 ++++++++++++--
 .../api/communication/ODataServerErrorException.java       | 11 ++++++++++-
 .../communication/header/ODataErrorResponseChecker.java    |  6 +++---
 .../communication/request/AsyncRequestWrapperImpl.java     |  2 +-
 5 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java
index e24796efa..5b29506ae 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java
@@ -78,7 +78,7 @@ public class TransactionalPersistenceManagerImpl extends AbstractPersistenceMana
     // This should be 202 for service version <= 3.0 and 200 for service version >= 4.0 but it seems that
     // many service implementations are not fully compliant in this respect.
     if (response.getStatusCode() != 202 && response.getStatusCode() != 200) {
-      throw new ODataServerErrorException(new ResponseStatusLine(response));
+      throw new ODataServerErrorException(new ResponseStatusLine(response), response.getRawResponse());
     }
 
     if (!items.isEmpty()) {
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataClientErrorException.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataClientErrorException.java
index 290f59f89..77063fb1f 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataClientErrorException.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataClientErrorException.java
@@ -23,6 +23,8 @@ import org.apache.http.StatusLine;
 import org.apache.olingo.commons.api.ex.ODataError;
 import org.apache.olingo.commons.api.ex.ODataRuntimeException;
 
+import java.io.InputStream;
+
 /**
  * Represents a client error in OData.
  *
@@ -38,16 +40,19 @@ public class ODataClientErrorException extends ODataRuntimeException {
   
   private Header[] headerInfo;
 
+  private InputStream rawResponse;
+
   /**
    * Constructor.
    *
    * @param statusLine request status info.
    */
-  public ODataClientErrorException(final StatusLine statusLine) {
+  public ODataClientErrorException(final StatusLine statusLine, final InputStream entity) {
     super(statusLine.toString());
 
     this.statusLine = statusLine;
     this.error = null;
+    this.rawResponse = entity;
   }
 
   /**
@@ -56,7 +61,7 @@ public class ODataClientErrorException extends ODataRuntimeException {
    * @param statusLine request status info.
    * @param error OData error to be wrapped.
    */
-  public ODataClientErrorException(final StatusLine statusLine, final ODataError error) {
+  public ODataClientErrorException(final StatusLine statusLine, final ODataError error, final InputStream entity) {
     super(error == null ?
         statusLine.toString() :
         (error.getCode() == null || error.getCode().isEmpty() ? "" : "(" + error.getCode() + ") ")
@@ -64,6 +69,7 @@ public class ODataClientErrorException extends ODataRuntimeException {
 
     this.statusLine = statusLine;
     this.error = error;
+    this.rawResponse = entity;
   }
 
   /**
@@ -99,4 +105,8 @@ public class ODataClientErrorException extends ODataRuntimeException {
   public Header[] getHeaderInfo() {
     return headerInfo;
   }
+
+  public InputStream getRawResponse() {
+    return rawResponse;
+  }
 }
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataServerErrorException.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataServerErrorException.java
index 932e3cb3b..32e20b55d 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataServerErrorException.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataServerErrorException.java
@@ -21,6 +21,8 @@ package org.apache.olingo.client.api.communication;
 import org.apache.http.StatusLine;
 import org.apache.olingo.commons.api.ex.ODataRuntimeException;
 
+import java.io.InputStream;
+
 /**
  * Represents a server error in OData.
  */
@@ -28,12 +30,19 @@ public class ODataServerErrorException extends ODataRuntimeException {
 
   private static final long serialVersionUID = -6423014532618680135L;
 
+  private InputStream rawResponse;
+
   /**
    * Constructor.
    *
    * @param statusLine request status info.
    */
-  public ODataServerErrorException(final StatusLine statusLine) {
+  public ODataServerErrorException(final StatusLine statusLine, final InputStream entity) {
     super(statusLine.toString());
+    this.rawResponse = entity;
+  }
+
+  public InputStream getRawResponse() {
+    return rawResponse;
   }
 }
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 1f8413ba0..2acba3abf 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
@@ -54,7 +54,7 @@ public final class ODataErrorResponseChecker {
     ODataRuntimeException result = null;
 
     if (entity == null) {
-      result = new ODataClientErrorException(statusLine);
+      result = new ODataClientErrorException(statusLine, entity);
     } else {
       final ContentType contentType = accept.contains("xml") ? ContentType.APPLICATION_ATOM_XML : ContentType.JSON;
 
@@ -94,9 +94,9 @@ public final class ODataErrorResponseChecker {
       if (statusLine.getStatusCode() >= 500 && error!= null && 
           (error.getDetails() == null || error.getDetails().isEmpty()) && 
           (error.getInnerError() == null || error.getInnerError().size() == 0)) {
-        result = new ODataServerErrorException(statusLine);
+        result = new ODataServerErrorException(statusLine, entity);
       } else {
-        result = new ODataClientErrorException(statusLine, error);
+        result = new ODataClientErrorException(statusLine, error, entity);
       }
     }
 
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestWrapperImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestWrapperImpl.java
index 924f47bed..48fb596d4 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestWrapperImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestWrapperImpl.java
@@ -231,7 +231,7 @@ public class AsyncRequestWrapperImpl<R extends ODataResponse> extends AbstractRe
       }
 
       if (response == null) {
-        throw new ODataClientErrorException(res == null ? null : res.getStatusLine());
+        throw new ODataClientErrorException(res == null ? null : res.getStatusLine(), response.getRawResponse());
       }
 
       return response;