mirror of https://github.com/halo-dev/halo
Refactor CommonController.
parent
7b480ca32e
commit
363acf467b
|
@ -43,7 +43,7 @@ public class PostCommentController {
|
||||||
|
|
||||||
@GetMapping("latest")
|
@GetMapping("latest")
|
||||||
@ApiOperation("Pages latest comments")
|
@ApiOperation("Pages latest comments")
|
||||||
public List<PostCommentWithPostVO> pageLatest(@RequestParam(name = "top", defaultValue = "10") int top,
|
public List<PostCommentWithPostVO> listLatest(@RequestParam(name = "top", defaultValue = "10") int top,
|
||||||
@RequestParam(name = "status", required = false) CommentStatus status) {
|
@RequestParam(name = "status", required = false) CommentStatus status) {
|
||||||
// Get latest comment
|
// Get latest comment
|
||||||
List<PostComment> content = postCommentService.pageLatest(top, status).getContent();
|
List<PostComment> content = postCommentService.pageLatest(top, status).getContent();
|
||||||
|
|
|
@ -6,12 +6,9 @@ import org.springframework.boot.web.servlet.error.ErrorController;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import run.halo.app.model.entity.User;
|
|
||||||
import run.halo.app.model.support.HaloConst;
|
|
||||||
import run.halo.app.service.ThemeService;
|
import run.halo.app.service.ThemeService;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpSession;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error page Controller
|
* Error page Controller
|
||||||
|
@ -29,8 +26,6 @@ public class CommonController implements ErrorController {
|
||||||
|
|
||||||
private static final String INTERNAL_ERROR_TEMPLATE = "500.ftl";
|
private static final String INTERNAL_ERROR_TEMPLATE = "500.ftl";
|
||||||
|
|
||||||
private static final String ADMIN_URL = "/admin";
|
|
||||||
|
|
||||||
private final ThemeService themeService;
|
private final ThemeService themeService;
|
||||||
|
|
||||||
public CommonController(ThemeService themeService) {
|
public CommonController(ThemeService themeService) {
|
||||||
|
@ -44,13 +39,9 @@ public class CommonController implements ErrorController {
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = ERROR_PATH)
|
@GetMapping(value = ERROR_PATH)
|
||||||
public String handleError(HttpServletRequest request, HttpSession session) {
|
public String handleError(HttpServletRequest request) {
|
||||||
final Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
|
final Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
|
||||||
|
|
||||||
final String requestURI = request.getRequestURI();
|
|
||||||
|
|
||||||
final User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
|
||||||
|
|
||||||
log.error("Error path: [{}], status: [{}]", getErrorPath(), statusCode);
|
log.error("Error path: [{}], status: [{}]", getErrorPath(), statusCode);
|
||||||
|
|
||||||
// Get the exception
|
// Get the exception
|
||||||
|
@ -62,40 +53,17 @@ public class CommonController implements ErrorController {
|
||||||
if (StringUtils.startsWithIgnoreCase(throwable.getMessage(), "Could not resolve view with name '")) {
|
if (StringUtils.startsWithIgnoreCase(throwable.getMessage(), "Could not resolve view with name '")) {
|
||||||
// TODO May cause unknown-reason problem
|
// TODO May cause unknown-reason problem
|
||||||
// if Ftl was not found then redirect to /404
|
// if Ftl was not found then redirect to /404
|
||||||
if (requestURI.contains(ADMIN_URL) && null != user) {
|
return "redirect:/404";
|
||||||
return "redirect:/admin/404";
|
|
||||||
} else {
|
|
||||||
return "redirect:/404";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (requestURI.contains(ADMIN_URL) && null != user) {
|
|
||||||
return "redirect:/admin/500";
|
if (statusCode == 500) {
|
||||||
} else {
|
|
||||||
return "redirect:/500";
|
return "redirect:/500";
|
||||||
|
} else {
|
||||||
|
return "redirect:/404";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Render 404 error page
|
|
||||||
*
|
|
||||||
* @return template path:
|
|
||||||
*/
|
|
||||||
@GetMapping(value = "/admin/404")
|
|
||||||
public String adminNotFround() {
|
|
||||||
return "common/error/404";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render 500 error page
|
|
||||||
*
|
|
||||||
* @return template path:
|
|
||||||
*/
|
|
||||||
@GetMapping(value = "/admin/500")
|
|
||||||
public String adminInternalError() {
|
|
||||||
return "common/error/500";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render 404 error page
|
* Render 404 error page
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue