|
|
|
@ -52,15 +52,15 @@ import java.io.IOException;
|
|
|
|
@ControllerAdvice(annotations = {NacosApi.class})
|
|
|
|
@ControllerAdvice(annotations = {NacosApi.class})
|
|
|
|
@ResponseBody
|
|
|
|
@ResponseBody
|
|
|
|
public class NacosApiExceptionHandler {
|
|
|
|
public class NacosApiExceptionHandler {
|
|
|
|
|
|
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(NacosApiExceptionHandler.class);
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(NacosApiExceptionHandler.class);
|
|
|
|
|
|
|
|
|
|
|
|
@ExceptionHandler(NacosApiException.class)
|
|
|
|
@ExceptionHandler(NacosApiException.class)
|
|
|
|
public ResponseEntity<Result<String>> handleNacosApiException(NacosApiException e) {
|
|
|
|
public ResponseEntity<Result<String>> handleNacosApiException(NacosApiException e) {
|
|
|
|
LOGGER.error("got exception. {} {}", e.getErrAbstract(), e.getErrMsg());
|
|
|
|
LOGGER.error("got exception. {} {}", e.getErrAbstract(), e.getErrMsg());
|
|
|
|
return ResponseEntity.status(e.getErrCode()).body(new Result<>(e.getDetailErrCode(), e.getErrAbstract(), e.getErrMsg()));
|
|
|
|
return ResponseEntity.status(e.getErrCode()).body(new Result<>(e.getDetailErrCode(), e.getErrAbstract(), e.getErrMsg()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ExceptionHandler(NacosException.class)
|
|
|
|
@ExceptionHandler(NacosException.class)
|
|
|
|
public ResponseEntity<Result<String>> handleNacosException(NacosException e) {
|
|
|
|
public ResponseEntity<Result<String>> handleNacosException(NacosException e) {
|
|
|
|
LOGGER.error("got exception. {}", e.getErrMsg());
|
|
|
|
LOGGER.error("got exception. {}", e.getErrMsg());
|
|
|
|
@ -72,63 +72,63 @@ public class NacosApiExceptionHandler {
|
|
|
|
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
|
|
|
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
|
|
|
return ResponseEntity.status(e.getErrCode()).body(Result.failure(ErrorCode.SERVER_ERROR, e.getMessage()));
|
|
|
|
return ResponseEntity.status(e.getErrCode()).body(Result.failure(ErrorCode.SERVER_ERROR, e.getMessage()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
|
@ExceptionHandler(HttpMessageNotReadableException.class)
|
|
|
|
@ExceptionHandler(HttpMessageNotReadableException.class)
|
|
|
|
public Result<String> handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {
|
|
|
|
public Result<String> handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {
|
|
|
|
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
|
|
|
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
|
|
|
return Result.failure(ErrorCode.PARAMETER_MISSING, e.getMessage());
|
|
|
|
return Result.failure(ErrorCode.PARAMETER_MISSING, e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
|
@ExceptionHandler(HttpMessageConversionException.class)
|
|
|
|
@ExceptionHandler(HttpMessageConversionException.class)
|
|
|
|
public Result<String> handleHttpMessageConversionException(HttpMessageConversionException e) {
|
|
|
|
public Result<String> handleHttpMessageConversionException(HttpMessageConversionException e) {
|
|
|
|
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
|
|
|
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
|
|
|
return Result.failure(ErrorCode.PARAMETER_VALIDATE_ERROR, e.getMessage());
|
|
|
|
return Result.failure(ErrorCode.PARAMETER_VALIDATE_ERROR, e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
|
@ExceptionHandler(NumberFormatException.class)
|
|
|
|
@ExceptionHandler(NumberFormatException.class)
|
|
|
|
public Result<String> handleNumberFormatException(NumberFormatException e) {
|
|
|
|
public Result<String> handleNumberFormatException(NumberFormatException e) {
|
|
|
|
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
|
|
|
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
|
|
|
return Result.failure(ErrorCode.PARAMETER_VALIDATE_ERROR, e.getMessage());
|
|
|
|
return Result.failure(ErrorCode.PARAMETER_VALIDATE_ERROR, e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
|
@ExceptionHandler(IllegalArgumentException.class)
|
|
|
|
@ExceptionHandler(IllegalArgumentException.class)
|
|
|
|
public Result<String> handleIllegalArgumentException(IllegalArgumentException e) {
|
|
|
|
public Result<String> handleIllegalArgumentException(IllegalArgumentException e) {
|
|
|
|
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
|
|
|
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
|
|
|
return Result.failure(ErrorCode.PARAMETER_VALIDATE_ERROR, e.getMessage());
|
|
|
|
return Result.failure(ErrorCode.PARAMETER_VALIDATE_ERROR, e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
|
@ExceptionHandler(MissingServletRequestParameterException.class)
|
|
|
|
@ExceptionHandler(MissingServletRequestParameterException.class)
|
|
|
|
public Result<String> handleMissingServletRequestParameterException(MissingServletRequestParameterException e) {
|
|
|
|
public Result<String> handleMissingServletRequestParameterException(MissingServletRequestParameterException e) {
|
|
|
|
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
|
|
|
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
|
|
|
return Result.failure(ErrorCode.PARAMETER_MISSING, e.getMessage());
|
|
|
|
return Result.failure(ErrorCode.PARAMETER_MISSING, e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
|
@ExceptionHandler(HttpMediaTypeException.class)
|
|
|
|
@ExceptionHandler(HttpMediaTypeException.class)
|
|
|
|
public Result<String> handleHttpMediaTypeException(HttpMediaTypeException e) {
|
|
|
|
public Result<String> handleHttpMediaTypeException(HttpMediaTypeException e) {
|
|
|
|
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
|
|
|
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
|
|
|
return Result.failure(ErrorCode.MEDIA_TYPE_ERROR, e.getMessage());
|
|
|
|
return Result.failure(ErrorCode.MEDIA_TYPE_ERROR, e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ResponseStatus(HttpStatus.FORBIDDEN)
|
|
|
|
@ResponseStatus(HttpStatus.FORBIDDEN)
|
|
|
|
@ExceptionHandler(AccessException.class)
|
|
|
|
@ExceptionHandler(AccessException.class)
|
|
|
|
public Result<String> handleAccessException(AccessException e) {
|
|
|
|
public Result<String> handleAccessException(AccessException e) {
|
|
|
|
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
|
|
|
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
|
|
|
return Result.failure(ErrorCode.ACCESS_DENIED, e.getErrMsg());
|
|
|
|
return Result.failure(ErrorCode.ACCESS_DENIED, e.getErrMsg());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
|
@ExceptionHandler(value = {DataAccessException.class, ServletException.class, IOException.class})
|
|
|
|
@ExceptionHandler(value = {DataAccessException.class, ServletException.class, IOException.class})
|
|
|
|
public Result<String> handleDataAccessException(Exception e) {
|
|
|
|
public Result<String> handleDataAccessException(Exception e) {
|
|
|
|
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
|
|
|
LOGGER.error("got exception. {} {}", e.getMessage(), ExceptionUtil.getAllExceptionMsg(e));
|
|
|
|
return Result.failure(ErrorCode.DATA_ACCESS_ERROR, e.getMessage());
|
|
|
|
return Result.failure(ErrorCode.DATA_ACCESS_ERROR, e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
|
@ExceptionHandler(Exception.class)
|
|
|
|
@ExceptionHandler(Exception.class)
|
|
|
|
public Result<String> handleOtherException(Exception e) {
|
|
|
|
public Result<String> handleOtherException(Exception e) {
|
|
|
|
|