Fix NullPointerException when getting ServletException

pull/137/head
johnniang 2019-03-02 21:41:09 +08:00
parent 773ebabad4
commit 562da7b04b
4 changed files with 7 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package cc.ryanc.halo.model.domain;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data; import lombok.Data;
import lombok.ToString;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
@ -18,6 +19,7 @@ import java.util.List;
* @date : 2018/1/12 * @date : 2018/1/12
*/ */
@Data @Data
@ToString
@Entity @Entity
@Table(name = "halo_tag") @Table(name = "halo_tag")
public class Tag implements Serializable { public class Tag implements Serializable {

View File

@ -2,6 +2,7 @@ package cc.ryanc.halo.model.domain;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data; import lombok.Data;
import lombok.ToString;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
@ -21,6 +22,7 @@ import java.util.Date;
* @date : 2017/11/14 * @date : 2017/11/14
*/ */
@Data @Data
@ToString
@Entity @Entity
@Table(name = "halo_user") @Table(name = "halo_user")
public class User implements Serializable { public class User implements Serializable {

View File

@ -53,7 +53,7 @@ public class ControllerExceptionHandler {
public JsonResult handleConstraintViolationException(ConstraintViolationException e) { public JsonResult handleConstraintViolationException(ConstraintViolationException e) {
JsonResult jsonResult = handleBaseException(e); JsonResult jsonResult = handleBaseException(e);
jsonResult.setCode(HttpStatus.BAD_REQUEST.value()); jsonResult.setCode(HttpStatus.BAD_REQUEST.value());
jsonResult.setMsg("Filed validation error"); jsonResult.setMsg("Field validation error");
jsonResult.setResult(e.getConstraintViolations()); jsonResult.setResult(e.getConstraintViolations());
return jsonResult; return jsonResult;
} }
@ -63,7 +63,7 @@ public class ControllerExceptionHandler {
public JsonResult handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { public JsonResult handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
JsonResult jsonResult = handleBaseException(e); JsonResult jsonResult = handleBaseException(e);
jsonResult.setCode(HttpStatus.BAD_REQUEST.value()); jsonResult.setCode(HttpStatus.BAD_REQUEST.value());
jsonResult.setMsg("Filed validation error"); jsonResult.setMsg("Field validation error");
Map<String, String> errMap = ValidationUtils.mapWithFieldError(e.getBindingResult().getFieldErrors()); Map<String, String> errMap = ValidationUtils.mapWithFieldError(e.getBindingResult().getFieldErrors());
jsonResult.setResult(errMap); jsonResult.setResult(errMap);
return jsonResult; return jsonResult;

View File

@ -39,7 +39,7 @@ public class CommonController implements ErrorController {
// Get the exception // Get the exception
Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception"); Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception");
if (StringUtils.startsWithIgnoreCase(throwable.getMessage(), "Could not resolve view with name '")) { if (throwable != null && StringUtils.startsWithIgnoreCase(throwable.getMessage(), "Could not resolve view with name '")) {
// TODO May cause unreasoned problem // TODO May cause unreasoned problem
// if Ftl was not found then redirect to /404 // if Ftl was not found then redirect to /404
return "redirect:/404"; return "redirect:/404";