From a93d49c1aa3fb57aa4aa3914b6b2aefe913fd067 Mon Sep 17 00:00:00 2001 From: Archana Rai Date: Wed, 11 Apr 2018 13:48:28 +0530 Subject: [PATCH] [OLINGO-1256]Error code improvements --- .../olingo/server/core/ODataExceptionHelper.java | 6 +++++- .../apache/olingo/server/core/ExceptionHelperTest.java | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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 1e0efb120..ce6e94eca 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) { 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 dffbf825b..10d29ace3 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() {