From: Jaroslav Tóth Date: Mon, 12 Aug 2019 14:55:05 +0000 (+0200) Subject: Fixed POST data error response X-Git-Tag: release/neon-sr3~16 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=netconf.git;a=commitdiff_plain;h=c5959bacd59a68939a59f5ce02e60947dc45a1cf Fixed POST data error response - Added correct error types and tags that previously weren't specified at all so it always returned 500 status code. Change-Id: I911fcd04546d2c2884f52e197c44cde67ed214a8 Signed-off-by: Jaroslav Tóth (cherry picked from commit 03fc9bee15c61a8d1cdc0768ef7c3bdfb781514b) --- diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java index 075fd1a09d..87b20ee86b 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java @@ -240,11 +240,13 @@ public class RestconfDataServiceImpl implements RestconfDataService { private static void checkQueryParams(final boolean insertUsed, final boolean pointUsed, final String insert) { if (pointUsed && !insertUsed) { - throw new RestconfDocumentedException("Point parameter can't be used without Insert parameter."); + throw new RestconfDocumentedException("Point parameter can't be used without Insert parameter.", + RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT); } if (pointUsed && (insert.equals("first") || insert.equals("last"))) { throw new RestconfDocumentedException( - "Point parameter can be used only with 'after' or 'before' values of Insert parameter."); + "Point parameter can be used only with 'after' or 'before' values of Insert parameter.", + RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT); } } @@ -269,7 +271,8 @@ public class RestconfDataServiceImpl implements RestconfDataService { insertUsed = true; insert = entry.getValue().iterator().next(); } else { - throw new RestconfDocumentedException("Insert parameter can be used only once."); + throw new RestconfDocumentedException("Insert parameter can be used only once.", + RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT); } break; case "point": @@ -277,11 +280,13 @@ public class RestconfDataServiceImpl implements RestconfDataService { pointUsed = true; point = entry.getValue().iterator().next(); } else { - throw new RestconfDocumentedException("Point parameter can be used only once."); + throw new RestconfDocumentedException("Point parameter can be used only once.", + RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT); } break; default: - throw new RestconfDocumentedException("Bad parameter for post: " + entry.getKey()); + throw new RestconfDocumentedException("Bad parameter for post: " + entry.getKey(), + RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT); } } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PostDataTransactionUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PostDataTransactionUtil.java index 6041081dba..937a6361a0 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PostDataTransactionUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PostDataTransactionUtil.java @@ -21,6 +21,7 @@ import org.opendaylight.mdsal.dom.api.DOMTransactionChain; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.common.context.NormalizedNodeContext; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; +import org.opendaylight.restconf.common.errors.RestconfError; import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler; import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef; import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper; @@ -209,7 +210,8 @@ public final class PostDataTransactionUtil { default: throw new RestconfDocumentedException( "Used bad value of insert parameter. Possible values are first, last, before or after, " - + "but was: " + insert); + + "but was: " + insert, RestconfError.ErrorType.PROTOCOL, + RestconfError.ErrorTag.BAD_ATTRIBUTE); } } }