Repository: olingo-odata4
Updated Branches:
  refs/heads/master aaff527dc -> a93d49c1a


[OLINGO-1256]Error code improvements


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/a93d49c1
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/a93d49c1
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/a93d49c1

Branch: refs/heads/master
Commit: a93d49c1aa3fb57aa4aa3914b6b2aefe913fd067
Parents: aaff527
Author: Archana Rai <archana....@sap.com>
Authored: Wed Apr 11 13:48:28 2018 +0530
Committer: Archana Rai <archana....@sap.com>
Committed: Wed Apr 11 13:48:28 2018 +0530

----------------------------------------------------------------------
 .../apache/olingo/server/core/ODataExceptionHelper.java   |  6 +++++-
 .../apache/olingo/server/core/ExceptionHelperTest.java    | 10 ++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a93d49c1/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java
 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java
index 1e0efb1..ce6e94e 100644
--- 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java
+++ 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java
@@ -132,7 +132,11 @@ public class ODataExceptionHelper {
   }
 
   public static ODataServerError createServerErrorObject(final 
ODataLibraryException e, final Locale requestedLocale) {
-    return basicTranslatedError(e, requestedLocale);
+    ODataServerError serverError = basicTranslatedError(e, requestedLocale);
+    if(e instanceof SerializerException || e instanceof DeserializerException){
+      serverError.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
+    }
+    return serverError;
   }
 
   public static ODataServerError createServerErrorObject(final 
ODataApplicationException e) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a93d49c1/lib/server-core/src/test/java/org/apache/olingo/server/core/ExceptionHelperTest.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/ExceptionHelperTest.java
 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/ExceptionHelperTest.java
index dffbf82..10d29ac 100644
--- 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/ExceptionHelperTest.java
+++ 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/ExceptionHelperTest.java
@@ -79,6 +79,16 @@ public class ExceptionHelperTest {
       checkStatusCode(serverError, HttpStatusCode.BAD_REQUEST, e);
     }
   }
+  
+  @Test
+  public void libraryExceptionLeadToBadRequest() {
+      ODataLibraryException e = new SerializerException(DEV_MSG, 
SerializerException.MessageKeys.MISSING_PROPERTY);
+      ODataServerError serverError = 
ODataExceptionHelper.createServerErrorObject(e, null);
+      checkStatusCode(serverError, HttpStatusCode.BAD_REQUEST, e);
+      e = new SerializerException(DEV_MSG, 
DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
+      serverError = ODataExceptionHelper.createServerErrorObject(e, null);
+      checkStatusCode(serverError, HttpStatusCode.BAD_REQUEST, e);
+  }
 
   @Test
   public void contentNegotiatorExceptionMustLeadToNotAcceptable() {

Reply via email to