Skip to content

Commit 5172986

Browse files
committed
Error Pages
1 parent 1c05a99 commit 5172986

File tree

9 files changed

+92
-10
lines changed

9 files changed

+92
-10
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.woehlke.simpleworklist.control.common;
2+
3+
import org.springframework.boot.web.servlet.error.ErrorController;
4+
import org.springframework.http.HttpStatus;
5+
import org.springframework.stereotype.Controller;
6+
import org.springframework.ui.Model;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
9+
import javax.servlet.RequestDispatcher;
10+
import javax.servlet.http.HttpServletRequest;
11+
12+
@Controller
13+
public class MyErrorController implements ErrorController {
14+
15+
@RequestMapping("/fehler")
16+
public String handleError(HttpServletRequest request, Model model) {
17+
Exception exception = (Exception) request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
18+
Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
19+
if (status != null) {
20+
Integer statusCode = Integer.valueOf(status.toString());
21+
if(statusCode == HttpStatus.NOT_FOUND.value()) {
22+
return "error/error-404";
23+
}
24+
else if(statusCode == HttpStatus.INTERNAL_SERVER_ERROR.value()) {
25+
return "error/error-500";
26+
}
27+
}
28+
model.addAttribute("exceptionMessage",exception.getLocalizedMessage());
29+
return "error/error";
30+
}
31+
32+
@Override
33+
public String getErrorPath() {
34+
return "/fehler";
35+
}
36+
}

src/main/java/org/woehlke/simpleworklist/oodm/services/impl/TaskServiceImpl.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,7 @@ public Page<Task> findByProject(Project thisProject, Context context, Pageable r
9696
LOGGER.info("---------------------------------");
9797
LOGGER.info("context: "+ context);
9898
LOGGER.info("---------------------------------");
99-
long projectContextId = 0;
100-
if (thisProject.getContext() != null){
101-
projectContextId = thisProject.getContext().getId().longValue();
102-
}
103-
long contextId = context.getId().longValue();
104-
if((thisProject == null)||(context ==null)||(projectContextId!=contextId)){
99+
if((thisProject == null)||(context ==null)){
105100
return new PageImpl<Task>(new ArrayList<Task>());
106101
} else {
107102
return taskRepository.findByProject(thisProject,request);

src/main/resources/static/css/main.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,11 @@ div#collapseDescription {
7979
#newUser2UserMessageForm {
8080
margin-bottom: 1rem;
8181
}
82+
83+
#tw-project-submenu-col {
84+
padding-top: 0.75rem;
85+
}
86+
87+
#tw-project-submenu-root {
88+
margin-top: 0.75rem;
89+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>We've got some trouble</title>
6+
</head>
7+
<body>
8+
<div class="cover">
9+
<h1>Our apologies.</h1>
10+
<p class="lead">This page stepped out for a quick ride.</p>
11+
<p>Please go back to our homepage to restart your browsing experience.</p>
12+
</div>
13+
</body>
14+
</html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<h1>Sorry, we couldn't find the page you're looking for.</h1>
5+
<a href="/">Go Home</a>
6+
</body>
7+
</html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<h1>(500) Something went wrong! </h1>
5+
<h2>Our Engineers are on it</h2>
6+
<div th:text="${exceptionMessage}">exceptionMessage</div>
7+
<a href="/">Go Home</a>
8+
</body>
9+
</html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<h1>Something went wrong! </h1>
5+
<h2>Our Engineers are on it</h2>
6+
<div th:text="${exceptionMessage}">exceptionMessage</div>
7+
<a href="/">Go Home</a>
8+
</body>
9+
</html>

src/main/resources/templates/layout/projects.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
xmlns:sd="http://www.thymeleaf.org/spring-data">
66

77
<section th:fragment="navigation-projects(rootCategories,thisProject)">
8-
<div class="container" id="projectNavigationWell" sec:authorize="isAuthenticated()">
9-
<hr/>
8+
<div class="border-top" id="projectNavigationWell" sec:authorize="isAuthenticated()">
9+
<div class="row col" id="tw-project-submenu-col">
1010
<nav>
1111
<ul id="rootProject">
1212
<li>
13-
<span>
13+
<span id="tw-project-submenu-root">
1414
<i class="fas fa-folder-open"></i>
1515
<a th:href="@{/project/root}" id="project_0"
1616
ondrop="drop2project(event)" ondragover="allowDrop2Project(event)"
@@ -24,6 +24,7 @@
2424
</li>
2525
</ul>
2626
</nav>
27+
</div>
2728
</div>
2829
</section>
2930

src/test/java/org/woehlke/simpleworklist/model/services/impl/UserAccountServiceImplTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.junit.Assert;
66

77
import org.junit.Test;
8+
import org.springframework.data.domain.PageRequest;
9+
import org.springframework.data.domain.Pageable;
810
import org.springframework.security.core.context.SecurityContextHolder;
911
import org.springframework.security.core.userdetails.UserDetails;
1012
import org.springframework.security.core.userdetails.UsernameNotFoundException;
@@ -90,7 +92,8 @@ public void testSaveAndFlush(){
9092
UserAccount user = userAccountService.findByUserEmail(email);
9193
Assert.assertTrue(user.getUserEmail().compareTo(email) == 0);
9294
}
93-
for(UserAccount user: userAccountService.findAll()){
95+
Pageable request = new PageRequest(0,10);
96+
for(UserAccount user: userAccountService.findAll(request)){
9497
Assert.assertNotNull(user.getId());
9598
Assert.assertNotNull(user.getUserEmail());
9699
Assert.assertNotNull(user.getUserPassword());

0 commit comments

Comments
 (0)