X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Frestconf-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Frestconf%2Fcommon%2Ferrors%2FRestconfDocumentedException.java;h=e0431f12b4534e5ed6fd532e4a3e5c6b3f8e7d2f;hb=a3b728740edbefe3e39b10f8512c7a977cfa69fa;hp=ac010cd659f60cd671e01e4a60eb6503bcf58895;hpb=d705d8e40d4a11c3ed0ca879128782dd6988eeb7;p=netconf.git diff --git a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/errors/RestconfDocumentedException.java b/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/errors/RestconfDocumentedException.java index ac010cd659..e0431f12b4 100644 --- a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/errors/RestconfDocumentedException.java +++ b/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/errors/RestconfDocumentedException.java @@ -22,8 +22,9 @@ import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; import org.opendaylight.yangtools.yang.common.OperationFailedException; import org.opendaylight.yangtools.yang.common.RpcError; -import org.opendaylight.yangtools.yang.common.YangError; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangNetconfError; +import org.opendaylight.yangtools.yang.data.api.YangNetconfErrorAware; /** * Unchecked exception to communicate error information, as defined in the ietf restcong draft, to be sent to the @@ -163,11 +164,16 @@ public class RestconfDocumentedException extends WebApplicationException { status = null; } + public RestconfDocumentedException(final Throwable cause, final List errors) { + super(cause, ErrorTags.statusOf(errors.get(0).getErrorTag())); + this.errors = ImmutableList.copyOf(errors); + status = null; + } + public static RestconfDocumentedException decodeAndThrow(final String message, final OperationFailedException cause) { for (final RpcError error : cause.getErrorList()) { - if (error.getErrorType() == RpcError.ErrorType.TRANSPORT - && error.getTag().equals(ErrorTag.RESOURCE_DENIED.elementBody())) { + if (error.getErrorType() == ErrorType.TRANSPORT && error.getTag().equals(ErrorTag.RESOURCE_DENIED)) { throw new RestconfDocumentedException(error.getMessage(), ErrorType.TRANSPORT, ErrorTags.RESOURCE_DENIED_TRANSPORT, cause); } @@ -230,16 +236,17 @@ public class RestconfDocumentedException extends WebApplicationException { } /** - * Throw an instance of this exception if the specified exception has a {@link YangError} attachment. + * Throw an instance of this exception if the specified exception has a {@link YangNetconfError} attachment. * * @param cause Proposed cause of a RestconfDocumented exception */ public static void throwIfYangError(final Throwable cause) { - if (cause instanceof YangError) { - final YangError error = (YangError) cause; - throw new RestconfDocumentedException(cause, new RestconfError(error.getErrorType().toNetconf(), - new ErrorTag(error.getErrorTag()), error.getErrorMessage().orElse(null), - error.getErrorAppTag().orElse(null))); + if (cause instanceof YangNetconfErrorAware) { + throw new RestconfDocumentedException(cause, ((YangNetconfErrorAware) cause).getNetconfErrors().stream() + .map(error -> new RestconfError(error.type(), error.tag(), error.message(), error.appTag(), + // FIXME: pass down error info + null, error.path())) + .collect(ImmutableList.toImmutableList())); } }