Skip to content

Commit e619627

Browse files
committed
Error handling added
1 parent c3d83e3 commit e619627

File tree

5 files changed

+54
-7
lines changed

5 files changed

+54
-7
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.olegshan.controllers;
2+
3+
import org.springframework.ui.Model;
4+
import org.springframework.web.bind.annotation.ControllerAdvice;
5+
import org.springframework.web.bind.annotation.ExceptionHandler;
6+
7+
/**
8+
* Created by olegshan on 20.10.2016.
9+
*/
10+
@ControllerAdvice
11+
public class ErrorHandler {
12+
13+
@ExceptionHandler(Exception.class)
14+
public String exception(Exception e, Model model) {
15+
model.addAttribute("errorMessage", e.getMessage());
16+
return "exception";
17+
}
18+
}

src/main/resources/application.properties

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ spring.datasource.url = jdbc:postgresql://localhost:5432/jparser
22
spring.datasource.username = postgres
33
spring.datasource.password = root
44
spring.jpa.show-sql = true
5-
spring.jpa.hibernate.ddl-auto = update
65

6+
spring.jpa.hibernate.ddl-auto = update
7+
spring.mvc.throw-exception-if-no-handler-found=true
8+
#spring.resources.add-mappings=false
79

810
#Amazon Elastic Beanstalk database settings, used in production mode:
911

1012
#spring.datasource.url = jdbc:postgresql://${RDS_HOSTNAME}:${RDS_PORT}/${RDS_DB_NAME}
1113
#spring.datasource.username = ${RDS_USERNAME}
1214
#spring.datasource.password = ${RDS_PASSWORD}
13-
#spring.thymeleaf.encoding=UTF-8
14-
#spring.jpa.hibernate.ddl-auto = update
15+
#spring.thymeleaf.encoding=UTF-8

src/main/resources/static/style.css

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
.logo {
2-
margin: 20px 0px 40px 10px;
2+
margin: 20px 0 40px 10px;
33
}
44

55
.logo h1, .logo span {
66
display: inline-block;
77
}
88

99
.logo h1 {
10-
margin-bottom: 0px;
10+
margin-bottom: 0;
1111
}
1212

1313
.logo p {
14-
margin-top: 0px;
14+
margin-top: 0;
1515
}
1616

1717
.logo small, .logo span, .logo p {
@@ -31,9 +31,13 @@
3131
}
3232

3333
.footer {
34-
margin: 40px 0px 40px 10px;
34+
margin: 40px 0 40px 10px;
3535
}
3636

3737
.table, .table td {
3838
border: hidden;
39+
}
40+
41+
.error {
42+
margin: 80px 0 80px 10px;
3943
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<html layout:decorator="layout" xmlns:layout="http://www.w3.org/1999/xhtml">
2+
3+
<div layout:fragment="content">
4+
<div class="error">
5+
<h1>
6+
<small>Sorry, an error occured</small>
7+
</h1>
8+
<p data-th-text="${errorMessage}"></p>
9+
<a href="/">Return to homepage</a>
10+
</div>
11+
</div>
12+
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<html layout:decorator="layout" xmlns:layout="http://www.w3.org/1999/xhtml">
2+
3+
<div layout:fragment="content">
4+
<div class="error">
5+
<h1>
6+
<small>Sorry, an error occured</small>
7+
</h1>
8+
<p data-th-text="${errorMessage}"></p>
9+
<a href="/">Return to homepage</a>
10+
</div>
11+
</div>
12+
</html>

0 commit comments

Comments
 (0)