From: Šimon Ukuš Date: Wed, 31 May 2023 08:48:03 +0000 (+0200) Subject: Throw NotFoundException on MissingSchemaSource X-Git-Tag: v6.0.0~62 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=e2651d0ba62aefcdc4a10b71f73098c6e28cef0c;p=netconf.git Throw NotFoundException on MissingSchemaSource Throwing NotFoundException, instead of a more general WebApplicationException, will return 404 status code to the client, rather than 500 with the WebAppException. JIRA: NETCONF-964 Change-Id: Ic72b068a477a98f618bf303c43d7deca94254f3e Signed-off-by: Šimon Ukuš --- diff --git a/netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibProvider.java b/netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibProvider.java index dfd783eb04..1a100aad27 100644 --- a/netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibProvider.java +++ b/netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibProvider.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; import java.util.concurrent.ExecutionException; +import javax.ws.rs.NotFoundException; import javax.ws.rs.WebApplicationException; import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.mdsal.binding.api.WriteTransaction; @@ -38,6 +39,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types. import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.yanglib.impl.rev141210.YanglibConfig; import org.opendaylight.yanglib.api.YangLibService; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException; import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation; import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource; @@ -195,6 +197,9 @@ public class YangLibProvider implements AutoCloseable, SchemaSourceListener, Yan final var yangTextSchemaSource = yangTextSchemaFuture.get(); return yangTextSchemaSource.asCharSource(StandardCharsets.UTF_8).read(); } catch (InterruptedException | ExecutionException e) { + if (e.getCause() instanceof MissingSchemaSourceException) { + throw new NotFoundException("Schema source " + sourceId + " not found", e); + } throw new WebApplicationException("Unable to get schema " + sourceId, e); } catch (IOException e) { throw new WebApplicationException("Unable to read schema " + sourceId, e);