Refactor exception handling 67/105867/8
authorŠimon Ukuš <simon.ukus@pantheon.tech>
Tue, 9 May 2023 13:14:16 +0000 (15:14 +0200)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Tue, 6 Jun 2023 08:31:56 +0000 (08:31 +0000)
Replace IllegalStateException with WebApplicationException when
the process of retrieving yang model fails.

This change has no impact on the status code being sent back
to the user, but changes the status reason phrase from
"Request failed" to "Internal Server Error".

JIRA: NETCONF-964
Change-Id: I7934141c481ddb01dab410d4d04d4b23555212ab
Signed-off-by: Šimon Ukuš <simon.ukus@pantheon.tech>
netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibProvider.java

index e1140a2153341dabed48dd5b24151c6db3b5f733..dfd783eb04b45e1afb003319b5f6d823c3266cfc 100644 (file)
@@ -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.WebApplicationException;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.WriteTransaction;
 import org.opendaylight.mdsal.common.api.CommitInfo;
@@ -194,9 +195,9 @@ public class YangLibProvider implements AutoCloseable, SchemaSourceListener, Yan
             final var yangTextSchemaSource = yangTextSchemaFuture.get();
             return yangTextSchemaSource.asCharSource(StandardCharsets.UTF_8).read();
         } catch (InterruptedException | ExecutionException e) {
-            throw new IllegalStateException("Unable to get schema " + sourceId, e);
+            throw new WebApplicationException("Unable to get schema " + sourceId, e);
         } catch (IOException e) {
-            throw new IllegalStateException("Unable to read schema " + sourceId, e);
+            throw new WebApplicationException("Unable to read schema " + sourceId, e);
         }
     }