You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
1.0 KiB
28 lines
1.0 KiB
package cn.edu.hactcm.common;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
|
import java.sql.SQLIntegrityConstraintViolationException;
|
|
|
|
@RestControllerAdvice(annotations = {Controller.class, RestController.class})
|
|
@Slf4j
|
|
public class GlobalExceptionHandler {
|
|
@ExceptionHandler(SQLIntegrityConstraintViolationException.class)
|
|
public R<String> ExceptionHandler(SQLIntegrityConstraintViolationException exception){
|
|
if (exception.getMessage().contains("Duplicate entry")) {
|
|
String[] split = exception.getMessage().split(" ");
|
|
return R.error(split[2] + "已存在");
|
|
}
|
|
return R.error("用户已存在");
|
|
}
|
|
|
|
@ExceptionHandler(CustomException.class)
|
|
public R<String> ExceptionHandler(CustomException exception){
|
|
return R.error(exception.getMessage());
|
|
}
|
|
}
|