Merge branch 'sakura_dev' of https://gitee.ltd/pigx/pigx into leng_dev

This commit is contained in:
冷冷 committed 2018-11-24 17:53:02 +08:00
commit d32090bf51
89 files changed
+675 -475

No files matched your search

@@ -17,6 +17,7 @@
package com.pig4cloud.pigx.common.security.component;
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
import com.pig4cloud.pigx.common.core.util.R;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -34,11 +35,10 @@ import java.util.List;
/**
* @author lengleng
* @date 2018/8/30
* 全局的的异常处理器
* 全局异常处理器
*/
@Slf4j
@RestControllerAdvice
@AllArgsConstructor
public class GlobalExceptionHandlerResolver {
/**
@@ -49,7 +49,7 @@ public class GlobalExceptionHandlerResolver {
*/
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public R exception(Exception e) {
public R handleGlobalException(Exception e) {
log.error("全局异常信息 ex={}", e.getMessage(), e);
return new R<>(e);
}
@@ -62,8 +62,12 @@ public class GlobalExceptionHandlerResolver {
*/
@ExceptionHandler(AccessDeniedException.class)
@ResponseStatus(HttpStatus.FORBIDDEN)
public R exception(AccessDeniedException e) {
return new R<>(e.getLocalizedMessage());
public R handleAccessDeniedException(AccessDeniedException e) {
log.error("拒绝授权异常信息 ex={}",e.getLocalizedMessage(),e);
return R.builder()
.msg(e.getLocalizedMessage())
.code(CommonConstant.FAIL)
.build();
}
/**
@@ -74,12 +78,12 @@ public class GlobalExceptionHandlerResolver {
*/
@ExceptionHandler({MethodArgumentNotValidException.class, BindException.class})
@ResponseStatus(HttpStatus.BAD_REQUEST)
public R bodyValidExceptionHandler(MethodArgumentNotValidException exception) {
public R handleBodyValidException(MethodArgumentNotValidException exception) {
List<FieldError> fieldErrors = exception.getBindingResult().getFieldErrors();
R result = new R();
result.setMsg(fieldErrors.get(0).getDefaultMessage());
log.warn(fieldErrors.get(0).getDefaultMessage());
return result;
log.error("参数绑定异常,ex = {}",fieldErrors.get(0).getDefaultMessage());
return R.builder()
.msg(fieldErrors.get(0).getDefaultMessage())
.code(CommonConstant.FAIL)
.build();
}
}
@@ -71,7 +71,7 @@ public class PigxWebResponseExceptionTranslator implements WebResponseExceptionT
ase = (HttpRequestMethodNotSupportedException) throwableAnalyzer
.getFirstThrowableOfType(HttpRequestMethodNotSupportedException.class, causeChain);
if (ase != null) {
return handleOAuth2Exception(new MethodNotAllowed(ase.getMessage(), ase));
return handleOAuth2Exception(new MethodNotAllowedException(ase.getMessage(), ase));
}
ase = (OAuth2Exception) throwableAnalyzer.getFirstThrowableOfType(
@@ -26,9 +26,9 @@ import org.springframework.http.HttpStatus;
* @date 2018/7/8
*/
@JsonSerialize(using = PigxAuth2ExceptionSerializer.class)
public class MethodNotAllowed extends PigxAuth2Exception {
public class MethodNotAllowedException extends PigxAuth2Exception {
public MethodNotAllowed(String msg, Throwable t) {
public MethodNotAllowedException(String msg, Throwable t) {
super(msg);
}