File tree 1 file changed +31
-0
lines changed
src/main/java/com/pidgeon/blog/controllers
1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .pidgeon .blog .controllers ;
2
+
3
+ import org .springframework .boot .autoconfigure .web .servlet .error .AbstractErrorController ;
4
+ import org .springframework .boot .web .servlet .error .ErrorAttributes ;
5
+ import org .springframework .http .MediaType ;
6
+ import org .springframework .stereotype .Controller ;
7
+ import org .springframework .web .bind .annotation .RequestMapping ;
8
+ import org .springframework .web .bind .annotation .ResponseBody ;
9
+
10
+ import javax .servlet .http .HttpServletRequest ;
11
+ import java .util .Map ;
12
+
13
+ @ Controller
14
+ public class CustomErrorController extends AbstractErrorController {
15
+
16
+ public CustomErrorController (ErrorAttributes errorAttributes ) {
17
+ super (errorAttributes );
18
+ }
19
+
20
+ @ RequestMapping (value = "/error" , produces = MediaType .APPLICATION_JSON_VALUE )
21
+ @ ResponseBody
22
+ public Map <String , Object > handleError (HttpServletRequest request ) {
23
+ Map <String , Object > errorAttributes = super .getErrorAttributes (request , false );
24
+ return errorAttributes ;
25
+ }
26
+
27
+ @ Override
28
+ public String getErrorPath () {
29
+ return "/error" ;
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments