@@ -113,7 +113,7 @@ private void createWorker(Coffig config) throws Exception {
113113
114114 .getMap ());
115115 } catch (RuntimeException e ) {
116- unwrapUndertowException (e );
116+ throw unwrapUndertowException (e );
117117 }
118118 }
119119
@@ -124,7 +124,7 @@ private void shutdownWorker() throws Exception {
124124 xnioWorker .awaitTermination (2 , TimeUnit .SECONDS );
125125 }
126126 } catch (RuntimeException e ) {
127- unwrapUndertowException (e );
127+ throw unwrapUndertowException (e );
128128 } finally {
129129 xnioWorker = null ;
130130 }
@@ -141,17 +141,21 @@ private void deploy(Coffig configuration) throws Exception {
141141 deploymentManager .deploy ();
142142 httpHandler = deploymentManager .start ();
143143 } catch (RuntimeException e ) {
144- unwrapUndertowException (e );
144+ throw unwrapUndertowException (e );
145145 }
146146 }
147147
148148 private void undeploy () throws Exception {
149149 if (deploymentManager != null ) {
150150 try {
151- deploymentManager .stop ();
152- deploymentManager .undeploy ();
151+ if (deploymentManager .getState () == DeploymentManager .State .STARTED ) {
152+ deploymentManager .stop ();
153+ }
154+ if (deploymentManager .getState () == DeploymentManager .State .DEPLOYED ) {
155+ deploymentManager .undeploy ();
156+ }
153157 } catch (ServletException | RuntimeException e ) {
154- unwrapUndertowException (e );
158+ throw unwrapUndertowException (e );
155159 } finally {
156160 httpHandler = null ;
157161 deploymentManager = null ;
@@ -170,7 +174,7 @@ private void start() throws Exception {
170174 undertow .start ();
171175 LOGGER .info ("Undertow Web server started" );
172176 } catch (RuntimeException e ) {
173- unwrapUndertowException (e );
177+ throw unwrapUndertowException (e );
174178 }
175179 }
176180
@@ -180,7 +184,7 @@ private void stop() throws Exception {
180184 undertow .stop ();
181185 LOGGER .info ("Undertow Web server stopped" );
182186 } catch (RuntimeException e ) {
183- unwrapUndertowException (e );
187+ throw unwrapUndertowException (e );
184188 } finally {
185189 undertow = null ;
186190 }
@@ -195,13 +199,13 @@ private UndertowPlugin getUndertowPlugin() {
195199 .orElseThrow (() -> SeedException .createNew (UndertowErrorCode .MISSING_UNDERTOW_PLUGIN ));
196200 }
197201
198- private void unwrapUndertowException (Exception e ) throws Exception {
202+ private Exception unwrapUndertowException (Exception e ) {
199203 if (e instanceof RuntimeException ) {
200204 Throwable cause = e .getCause ();
201205 if (cause instanceof Exception ) {
202- throw Seed .translateException ((Exception ) cause );
206+ return Seed .translateException ((Exception ) cause );
203207 }
204208 }
205- throw e ;
209+ return e ;
206210 }
207211}
0 commit comments