You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2015-03-27-error-handling.md
+72-2Lines changed: 72 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,6 @@ Otherwise ErrorHandler will fallback to itself to handle the exception.
13
13
By default each Application instance comes with a [DefaultErrorHandler]({{ site.coreurl }}/src/main/java/ro/pippo/core/DefaultErrorHandler.java)
14
14
that integrates with the `TemplateEngine` & `ContentTypeEngine`. It generates a representation of an exception or error result.
15
15
16
-
17
16
See below an custom ErrorHandler in action:
18
17
```java
19
18
publicclassBasicApplicationextendsApplication {
@@ -54,4 +53,75 @@ public class BasicApplication extends Application {
54
53
}
55
54
```
56
55
57
-
If you want to customize the template content for the default error templates (see the list of templates names in [TemplateEngine]({{ site.coreurl }}/src/main/java/ro/pippo/core/TemplateEngine.java)) then create a template with the same name in `src/main/resources/templates` folder.
56
+
If you want to customize the template content for the default error templates (see the list of templates names in [TemplateEngine]({{ site.coreurl }}/src/main/java/ro/pippo/core/TemplateEngine.java)) then create a template with the same name in `src/main/resources/templates` folder.
57
+
58
+
So, by default, the following templates are available (copy/paste from `TemplateEngine.java`):
Each template engine implementation comes with above templates. For example if we take a look at `pippo-template-parent/pippo-freemarker/src/main/resources` we can see:
76
+
```
77
+
$ tree .
78
+
.
79
+
└── templates
80
+
└── pippo
81
+
├── 000base.ftl
82
+
├── 400badRequest.ftl
83
+
├── 401unauthorized.ftl
84
+
├── 402paymentRequired.ftl
85
+
├── 403forbidden.ftl
86
+
├── 404notFound.ftl
87
+
├── 405methodNotAllowed.ftl
88
+
├── 409conflict.ftl
89
+
├── 410gone.ftl
90
+
├── 500internalError.ftl
91
+
├── 501notImplemented.ftl
92
+
├── 502overloaded.ftl
93
+
└── 503serviceUnavailable.ftl
94
+
```
95
+
96
+
If you use `FreemarkerTemplateEngine` in your application and you want to replace/override the content of `404notFound.ftl` template,
97
+
then place your variant of `404notFound.ftl` in your `src/main/resources/templates/pippo` directory.
98
+
99
+
If you are not happy with this fine granularity (a template for each HTTP error code), then you can create your custom `ErrorHandler` that returns the same template for any status code:
0 commit comments