@@ -63,7 +63,7 @@ HTTP status code will be set too.
6363
6464## custom err handler
6565
66- If the default view resolution and/or err model isn't enough, you can create your own err handler.
66+ If the default view resolution and/or err model isn't enough, you can create your own err handler:
6767
6868``` java
6969{
@@ -75,9 +75,48 @@ If the default view resolution and/or err model isn't enough, you can create you
7575}
7676```
7777
78- Err handler are executed in the order they were provided (like routes, parser and renderers).
78+ Err handler are executed in the order they were provided (like routes, parsers and renderers).
7979The first err handler that send an output wins!
8080
81+ ### catch specific exception or status code
82+
83+
84+ ``` java
85+ {
86+ err(MyException1 . class, (req, rsp, err) - > {
87+ MyException1 cause = (MyException1 ) err. getCause();
88+ // handle MyException1
89+ });
90+
91+ err(MyException2 . class, (req, rsp, err) - > {
92+ MyException2 cause = (MyException2 ) err. getCause();
93+ // handle MyException2
94+ });
95+
96+ err((req, rsp, err) - > {
97+ // handle any other exception
98+ });
99+ }
100+ ```
101+
102+ Or you can catch exception base on their response status code (see next section):
103+
104+ ``` java
105+ {
106+ err(404 , (req, rsp, err) - > {
107+ // handle 404
108+ });
109+
110+ err(503 , (req, rsp, err) - > {
111+ // handle 503
112+ });
113+
114+ err((req, rsp, err) - > {
115+ // handle any other exception
116+ });
117+ }
118+ ```
119+
81120## status code
82121
83122Default status code is ``` 500 ``` , except for:
@@ -106,6 +145,4 @@ or add a new entry in the ```application.conf``` file:
106145err.com.security.Forbidden = 403
107146```
108147
109- ``` java
110- throw new Forbidden ();
111- ```
148+ So, now if you throw a ``` com.security.Forbidden ``` exception the status code will be ``` 403 ``` .
0 commit comments