Migliorati check di system/ok
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package it.integry.ems.exception;
|
||||
|
||||
public class SystemNotInitializedException extends Exception {
|
||||
|
||||
private int statusCode;
|
||||
|
||||
public SystemNotInitializedException(int statusCode, String message) {
|
||||
super(message);
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
public int getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package it.integry.ems.system;
|
||||
|
||||
import it.integry.ems.exception.SystemNotInitializedException;
|
||||
import it.integry.ems.response.ServiceRestResponse;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -28,6 +29,11 @@ public class GlobalExceptionHandler {
|
||||
@ExceptionHandler({Exception.class})
|
||||
public @ResponseBody
|
||||
ServiceRestResponse handleException(HttpServletRequest request, HttpServletResponse response, Exception ex) {
|
||||
if (ex instanceof RuntimeException) {
|
||||
if (ex.getCause() instanceof SystemNotInitializedException)
|
||||
response.setStatus(((SystemNotInitializedException) ex.getCause()).getStatusCode());
|
||||
}
|
||||
|
||||
logger.error(request.getRequestURI(), ex);
|
||||
return ServiceRestResponse.createNegativeResponse(ex);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.annimon.stream.Stream;
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.common.var.EmsDBConst;
|
||||
import it.integry.ems._context.EmsCoreContext;
|
||||
import it.integry.ems.exception.SystemNotInitializedException;
|
||||
import it.integry.ems.settings.Model.AvailableConnectionsModel;
|
||||
import it.integry.ems.settings.Model.SettingsModel;
|
||||
import it.integry.ems_model.utility.UtilityHashMap;
|
||||
@@ -48,8 +49,7 @@ public class SystemRequisiteCheckInterceptor extends HandlerInterceptorAdapter {
|
||||
!serviceName.contains("favicon.ico")) {
|
||||
|
||||
if (!emsCoreContext.isContextInitialized()) {
|
||||
response.sendError(551, "System not initialized yet");
|
||||
return false;
|
||||
throw new SystemNotInitializedException(551, "System not initialized yet");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,8 @@ public class SystemRequisiteCheckInterceptor extends HandlerInterceptorAdapter {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user