Skip to content

Commit 0d33f95

Browse files
committed
Add CustomErrorController
1 parent 5f89732 commit 0d33f95

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}

0 commit comments

Comments
 (0)