Update RESTCONF error mapping
[netconf.git] / restconf / restconf-common / src / main / java / org / opendaylight / restconf / common / errors / RestconfError.java
index d88652b9149af9600f45d319079659125eb9fe7d..13eb681aacf497f6bbd0a434f19b327b6bee0665 100644 (file)
@@ -11,6 +11,7 @@ import static java.util.Objects.requireNonNull;
 
 import java.io.Serializable;
 import java.util.Locale;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.slf4j.Logger;
@@ -30,6 +31,7 @@ public class RestconfError implements Serializable {
     private static final Logger LOG = LoggerFactory.getLogger(RestconfError.class);
     private static final long serialVersionUID = 1L;
 
+    // FIXME: remove this enum in favor of RpcError.ErrorType (or its equivalent)
     public enum ErrorType {
         /**
          * Errors relating to the transport layer.
@@ -59,6 +61,20 @@ public class RestconfError implements Serializable {
                 return APPLICATION;
             }
         }
+
+        public static @NonNull ErrorType valueOf(final RpcError.ErrorType errorType) {
+            switch (errorType) {
+                case PROTOCOL:
+                    return PROTOCOL;
+                case RPC:
+                    return RPC;
+                case TRANSPORT:
+                    return TRANSPORT;
+                case APPLICATION:
+                default:
+                    return APPLICATION;
+            }
+        }
     }
 
     public enum ErrorTag {