Report 404 instead of 409 when listener is not found 10/108810/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 1 Nov 2023 17:56:55 +0000 (18:56 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 1 Nov 2023 17:58:10 +0000 (18:58 +0100)
When we fail to find the stream we should just return 404, not muck with
RestconfDocumentedException.

JIRA: NETCONF-1102
Change-Id: I63e761ef01141b23cd4b67b97aa0e5b32e86dcd1
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataStreamServiceImpl.java

index efc58fa41af3c026e9d741b5a069f0699eb25beb..81b94bd961a3147323ea542991dc24ba15499d5e 100644 (file)
@@ -17,17 +17,16 @@ import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.sse.Sse;
 import javax.ws.rs.sse.SseEventSink;
 import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
-import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.streams.ListenersBroker;
 import org.opendaylight.restconf.nb.rfc8040.streams.SSESessionHandler;
 import org.opendaylight.restconf.nb.rfc8040.streams.StreamsConfiguration;
-import org.opendaylight.yangtools.yang.common.ErrorTag;
-import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -67,7 +66,7 @@ public final class RestconfDataStreamServiceImpl {
         final var listener = listenersBroker.listenerFor(streamName);
         if (listener == null) {
             LOG.debug("Listener for stream with name {} was not found.", streamName);
-            throw new RestconfDocumentedException("Data missing", ErrorType.APPLICATION, ErrorTag.DATA_MISSING);
+            throw new WebApplicationException("No such stream: " + streamName, Status.NOT_FOUND);
         }
 
         LOG.debug("Listener for stream with name {} has been found, SSE session handler will be created.", streamName);