Revize ab32fe33
Přidáno uživatelem Petr Urban před téměř 3 roky(ů)
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/AppController.java | ||
---|---|---|
258 | 258 |
List<String> allConfigurationNames = configurationService.getAllConfigurationNames(); |
259 | 259 |
if (newConfigName == null || newConfigName.length() == 0 || allConfigurationNames.contains(newConfigName)) { |
260 | 260 |
model.addAttribute("configurations", configurationService.getConfigurationByName(currentConfigurationName)); |
261 |
model.addAttribute("errorMessage", "Configuration name is not possible."); |
|
261 |
model.addAttribute("errorMessage", "Configuration name was not entered!"); |
|
262 |
model.addAttribute("query", query); |
|
262 | 263 |
return "configuration"; |
263 | 264 |
} |
264 | 265 |
|
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/exception/CustomErrorController.java | ||
---|---|---|
1 | 1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.exception; |
2 | 2 |
|
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Query; |
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.AntiPatternService; |
|
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.ProjectService; |
|
3 | 6 |
import org.slf4j.Logger; |
4 | 7 |
import org.slf4j.LoggerFactory; |
8 |
import org.springframework.beans.factory.annotation.Autowired; |
|
5 | 9 |
import org.springframework.boot.web.servlet.error.ErrorController; |
6 | 10 |
import org.springframework.http.HttpStatus; |
7 | 11 |
import org.springframework.stereotype.Controller; |
12 |
import org.springframework.ui.Model; |
|
8 | 13 |
import org.springframework.web.bind.annotation.RequestMapping; |
9 | 14 |
import org.springframework.web.bind.annotation.ResponseBody; |
10 | 15 |
|
... | ... | |
16 | 21 |
|
17 | 22 |
private static final Logger LOGGER = LoggerFactory.getLogger(CustomErrorController.class); |
18 | 23 |
|
24 |
@Autowired |
|
25 |
private AntiPatternService antiPatternService; |
|
26 |
|
|
27 |
@Autowired |
|
28 |
private ProjectService projectService; |
|
29 |
|
|
19 | 30 |
|
20 | 31 |
@RequestMapping("/error") |
21 |
public String handleError(HttpServletRequest request) { |
|
32 |
public String handleError(HttpServletRequest request, Model model) {
|
|
22 | 33 |
|
23 | 34 |
String errorPage = "error"; |
24 | 35 |
|
25 |
Object statusCode = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); |
|
36 |
final Object statusCode = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); |
|
37 |
final Exception exception = (Exception) request.getAttribute(RequestDispatcher.ERROR_EXCEPTION); |
|
38 |
|
|
26 | 39 |
|
27 | 40 |
if (statusCode != null) { |
28 |
int code = Integer.parseInt(statusCode.toString()); |
|
41 |
final int code = Integer.parseInt(statusCode.toString());
|
|
29 | 42 |
|
30 | 43 |
if (code == HttpStatus.INTERNAL_SERVER_ERROR.value()) { |
31 |
return "error/500";
|
|
44 |
errorPage = "error/500";
|
|
32 | 45 |
} else if (code == HttpStatus.NOT_FOUND.value()) { |
33 |
return "error/404";
|
|
46 |
errorPage = "error/404";
|
|
34 | 47 |
} else if (code == HttpStatus.UNAUTHORIZED.value()) { |
35 |
return "error/403";
|
|
48 |
errorPage = "error/403";
|
|
36 | 49 |
} |
37 | 50 |
} |
38 | 51 |
|
52 |
model.addAttribute("query", new Query(projectService.getAllProjects(), antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns()))); |
|
53 |
model.addAttribute("antiPatterns", antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns())); |
|
54 |
|
|
55 |
if (exception != null) { |
|
56 |
model.addAttribute("errorMsg", exception.getLocalizedMessage()); |
|
57 |
} |
|
58 |
|
|
39 | 59 |
return errorPage; |
40 | 60 |
} |
41 | 61 |
|
src/main/webapp/WEB-INF/templates/error.html | ||
---|---|---|
8 | 8 |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"> |
9 | 9 |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> |
10 | 10 |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script> |
11 |
|
|
12 |
<script th:src="@{/resources/js/core.js}"></script> |
|
13 | 11 |
</head> |
14 | 12 |
<body> |
15 | 13 |
|
16 | 14 |
<div th:replace="fragments/navbar :: navBar"></div> |
17 | 15 |
|
18 |
<h1>Uncaught error</h1> |
|
16 |
<div class="d-flex align-items-center justify-content-center"> |
|
17 |
<div class="err-div"> |
|
18 |
<h1 class="err-text">Uncaught Application Error</h1> |
|
19 |
<p class="err-text">An Uncaught Error has occurred.</p> |
|
20 |
</div> |
|
21 |
</div> |
|
22 |
<div th:if="${errorMsg != null}" class="row d-flex align-items-center justify-content-center"> |
|
23 |
<h2 class="err-text">Cause</h2> |
|
24 |
<p class="err-text" th:text="${errorMsg}"></p> |
|
25 |
</div> |
|
26 |
|
|
27 |
<!-- Scripts --> |
|
28 |
<script th:src="@{/resources/js/login.js}"></script> |
|
29 |
<!-- ./Scripts --> |
|
19 | 30 |
|
20 | 31 |
</body> |
21 | 32 |
</html> |
src/main/webapp/WEB-INF/templates/error/403.html | ||
---|---|---|
15 | 15 |
|
16 | 16 |
<div th:replace="fragments/navbar :: navBar"></div> |
17 | 17 |
|
18 |
<h1>Not accessible with your current user role.</h1> |
|
18 |
<div class="d-flex align-items-center justify-content-center"> |
|
19 |
<div class="err-div"> |
|
20 |
<h1 class="err-text">403 - Not Authorized</h1> |
|
21 |
<p class="err-text">You don't seem to have permission to be here!</p> |
|
22 |
</div> |
|
23 |
</div> |
|
24 |
<div th:if="${errorMsg != null}" class="row d-flex align-items-center justify-content-center"> |
|
25 |
<h2 class="err-text">Cause</h2> |
|
26 |
<p class="err-text" th:text="${errorMsg}"></p> |
|
27 |
</div> |
|
28 |
|
|
29 |
<!-- Scripts --> |
|
30 |
<script th:src="@{/resources/js/login.js}"></script> |
|
31 |
<!-- ./Scripts --> |
|
19 | 32 |
|
20 | 33 |
</body> |
21 | 34 |
</html> |
src/main/webapp/WEB-INF/templates/error/404.html | ||
---|---|---|
14 | 14 |
<body> |
15 | 15 |
<div th:replace="fragments/navbar :: navBar"></div> |
16 | 16 |
|
17 |
<h1>The page you have requested could not be found</h1> |
|
17 |
<div class="d-flex align-items-center justify-content-center"> |
|
18 |
<div class="err-div"> |
|
19 |
<h1 class="err-text">404 - Content Not Found</h1> |
|
20 |
<p class="err-text">The specific content does not seem to be here...</p> |
|
21 |
</div> |
|
22 |
</div> |
|
23 |
<div th:if="${errorMsg != null}" class="row d-flex align-items-center justify-content-center"> |
|
24 |
<h2 class="err-text">Cause</h2> |
|
25 |
<p class="err-text" th:text="${errorMsg}"></p> |
|
26 |
</div> |
|
27 |
|
|
28 |
<!-- Scripts --> |
|
29 |
<script th:src="@{/resources/js/login.js}"></script> |
|
30 |
<!-- ./Scripts --> |
|
18 | 31 |
|
19 | 32 |
</body> |
20 | 33 |
</html> |
src/main/webapp/WEB-INF/templates/error/500.html | ||
---|---|---|
14 | 14 |
<body> |
15 | 15 |
<div th:replace="fragments/navbar :: navBar"></div> |
16 | 16 |
|
17 |
<h1>We are sorry for the error</h1> |
|
17 |
<div class="d-flex align-items-center justify-content-center"> |
|
18 |
<div class="err-div"> |
|
19 |
<h1 class="err-text">500 - Internal Server Error</h1> |
|
20 |
<p class="err-text">An Internal Server Error has occurred.</p> |
|
21 |
</div> |
|
22 |
</div> |
|
23 |
<div th:if="${errorMsg != null}" class="row d-flex align-items-center justify-content-center"> |
|
24 |
<h2 class="err-text">Cause</h2> |
|
25 |
<p class="err-text" th:text="${errorMsg}"></p> |
|
26 |
</div> |
|
27 |
|
|
28 |
<!-- Scripts --> |
|
29 |
<script th:src="@{/resources/js/login.js}"></script> |
|
30 |
<!-- ./Scripts --> |
|
18 | 31 |
|
19 | 32 |
</body> |
20 | 33 |
</html> |
src/main/webapp/WEB-INF/templates/fragments/navbar.html | ||
---|---|---|
1 | 1 |
<div th:fragment="navBar" xmlns:th="http://www.w3.org/1999/xhtml"> |
2 | 2 |
<nav class="navbar fixed-top navbar-expand-lg navbar-light bg-light" id="main-navbar"> |
3 |
<a class="navbar-brand"><b>SPAWn</b> – SPADe Web Interface</a> |
|
3 |
<a th:href="@{/}" class="navbar-brand"><b>SPAWn</b> – SPADe Web Interface</a>
|
|
4 | 4 |
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> |
5 | 5 |
<span class="navbar-toggler-icon"></span> |
6 | 6 |
</button> |
src/main/webapp/resources/css/style.css | ||
---|---|---|
171 | 171 |
margin-right: 1em; |
172 | 172 |
} |
173 | 173 |
|
174 |
.err-div { |
|
175 |
background-color: rgb(238, 238, 238); |
|
176 |
border-radius: 10px; |
|
177 |
width: 80%; |
|
178 |
margin: 0 auto; |
|
179 |
} |
|
180 |
|
|
181 |
.err-text { |
|
182 |
text-align: center; |
|
183 |
font-weight: 500; |
|
184 |
} |
|
185 |
|
Také k dispozici: Unified diff
#25 created and customized error templates.