[已解决]怎么解决:dubbo远程调用抛出的自定义异常在controller异常处理处接收到的异常类型不是自定义异常类型

服务模块提供如下方法,抛出如下自定义异常BusinessException

@Service
public class MerchantServiceImpl implements MerchantService {
        //...
        if(count>0){
        throw  new BusinessException(CommonErrorCode.E_100113);
        }
        //...
    }
}

controller模块通过dubbo注解调用上述方法

@Reference
private MerchantService merchantService;
//...
merchantService.createMerchant(merchantDTO);
//...

异常发生后会转到如下异常处理器

@ControllerAdvice
public class GlobalExceptionHandler {
 @ExceptionHandler(value = Exception.class)
    @ResponseBody
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public RestErrorResponse processException(HttpServletRequest request, HttpServletResponse response,Exception e){
        if(e instanceof BusinessException){
            ErrorCode errorCode = ((BusinessException) e).getErrorCode();
            int code = errorCode.getCode();
            String desc = errorCode.getDesc();

            return new RestErrorResponse(String.valueOf(code),desc);
        }
        LOGGER.error("系统异常",e);
        return new RestErrorResponse(String.valueOf(CommonErrorCode.UNKNOWN.getCode()),CommonErrorCode.UNKNOWN.getDesc());

    }
}

期望效果是接收到的异常类型满足if条件,但是实际接收的异常类型类型名重复且被换行分割了导致不满足if条件:

怎么解决:dubbo远程调用抛出的自定义异常在controller异常处理处接收到的异常类型不是自定义异常类型

讨论数量: 1

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!