[OLINGO-1256]Error code improvements

This commit is contained in:
Archana Rai 2018-04-11 13:48:28 +05:30
parent aaff527dcd
commit a93d49c1aa
2 changed files with 15 additions and 1 deletions

View File

@ -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) {

View File

@ -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() {