Browse Source

错误信息处理

yingp 8 years ago
parent
commit
7ef8bb5008
1 changed files with 8 additions and 0 deletions
  1. 8 0
      src/main/java/com/uas/erp/database/config/ExceptionConfig.java

+ 8 - 0
src/main/java/com/uas/erp/database/config/ExceptionConfig.java

@@ -2,11 +2,13 @@ package com.uas.erp.database.config;
 
 import com.uas.erp.database.web.ResponseWrap;
 import org.springframework.http.ResponseEntity;
+import org.springframework.jdbc.UncategorizedSQLException;
 import org.springframework.web.bind.annotation.ControllerAdvice;
 import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.ResponseBody;
 
 import javax.servlet.http.HttpServletRequest;
+import java.sql.SQLException;
 
 /**
  * Created by Pro1 on 2017/6/22.
@@ -14,6 +16,12 @@ import javax.servlet.http.HttpServletRequest;
 @ControllerAdvice
 public class ExceptionConfig {
 
+    @ExceptionHandler(value = UncategorizedSQLException.class)
+    @ResponseBody
+    public ResponseEntity sqlErrorHandler(HttpServletRequest req, UncategorizedSQLException e) throws Exception {
+        return ResponseWrap.badRequest(e.getSQLException().getMessage());
+    }
+
     @ExceptionHandler(value = Exception.class)
     @ResponseBody
     public ResponseEntity defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception {