Fixed POST data error response 57/83757/2
authorJaroslav Tóth <jtoth@frinx.io>
Mon, 12 Aug 2019 14:55:05 +0000 (16:55 +0200)
committerRobert Varga <nite@hq.sk>
Thu, 5 Sep 2019 14:03:19 +0000 (14:03 +0000)
- 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 <jtoth@frinx.io>
(cherry picked from commit 03fc9bee15c61a8d1cdc0768ef7c3bdfb781514b)

restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PostDataTransactionUtil.java

index 075fd1a09dcbeab16814071f8a1bc8466d10c7cd..87b20ee86bf8734a32f131d066cbb11dd93fbb35 100644 (file)
@@ -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);
             }
         }
 
index 6041081dba03eaa0f8df669115090e7824e583b1..937a6361a0b31e583c63c98398083006f8958997 100644 (file)
@@ -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);
             }
         }
     }