import static java.util.Objects.requireNonNull;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
import java.io.InputStream;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.common.errors.RestconfError;
+import org.opendaylight.yangtools.yang.data.api.YangNetconfError;
+import org.opendaylight.yangtools.yang.data.api.YangNetconfErrorAware;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* An abstract request body backed by an {@link InputStream}.
*/
-public abstract sealed class AbstractBody implements AutoCloseable permits OperationInputBody, PatchBody, ResourceBody {
+public abstract sealed class AbstractBody implements AutoCloseable
+ permits ChildBody, DataPostBody, OperationInputBody, PatchBody, ResourceBody {
private static final Logger LOG = LoggerFactory.getLogger(AbstractBody.class);
private static final VarHandle INPUT_STREAM;
}
@SuppressWarnings("unused")
+ @SuppressFBWarnings(value = "URF_UNREAD_FIELD", justification = "https://github.com/spotbugs/spotbugs/issues/2749")
private volatile InputStream inputStream;
AbstractBody(final InputStream inputStream) {
return is;
}
+
+ /**
+ * Throw a {@link RestconfDocumentedException} if the specified exception has a {@link YangNetconfError} attachment.
+ *
+ * @param cause Proposed cause of a RestconfDocumentedException
+ */
+ static void throwIfYangError(final Exception cause) {
+ if (cause instanceof YangNetconfErrorAware infoAware) {
+ throw new RestconfDocumentedException(cause, infoAware.getNetconfErrors().stream()
+ .map(error -> new RestconfError(error.type(), error.tag(), error.message(), error.appTag(),
+ // FIXME: pass down error info
+ null, error.path()))
+ .toList());
+ }
+ }
+
private @Nullable InputStream getStream() {
return (InputStream) INPUT_STREAM.getAndSet(this, null);
}