|
|
@@ -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 {
|