fix:修改异常提示

This commit is contained in:
石崇礼 2025-03-26 13:01:53 +08:00
parent ee2115e367
commit 503ff3a73e
2 changed files with 13 additions and 6 deletions

View File

@ -60,7 +60,7 @@ public class ControllerAdvice {
*/ */
@ExceptionHandler(value = NullPointerException.class) @ExceptionHandler(value = NullPointerException.class)
public Result<String> nullPointException(NullPointerException nullPointerException) { public Result<String> nullPointException(NullPointerException nullPointerException) {
log.error("空指针异常类型: {},信息: {}", nullPointerException.getClass(),nullPointerException.getMessage()); log.error("空指针异常类型: {},信息: {}", nullPointerException.getClass(), nullPointerException);
return Result.error(ErrorEnum.NULL_POINTER_EXCEPTION); return Result.error(ErrorEnum.NULL_POINTER_EXCEPTION);
} }
@ -86,7 +86,7 @@ public class ControllerAdvice {
*/ */
@ExceptionHandler(value = HttpMessageNotReadableException.class) @ExceptionHandler(value = HttpMessageNotReadableException.class)
public Result<String> httpMessageNotReadAbleException(HttpMessageNotReadableException e){ public Result<String> httpMessageNotReadAbleException(HttpMessageNotReadableException e){
log.warn("异常类型: {} 无可读信息: {}", e.getClass(), e.getMessage()); log.warn("异常类型: {} 无可读信息: ", e.getClass(), e);
return Result.error(ErrorEnum.HTTP_MESSAGE_NOT_READABLE_EXCEPTION); return Result.error(ErrorEnum.HTTP_MESSAGE_NOT_READABLE_EXCEPTION);
} }
@ -97,7 +97,7 @@ public class ControllerAdvice {
*/ */
@ExceptionHandler(value = RuntimeException.class) @ExceptionHandler(value = RuntimeException.class)
public Result<String> runtimeException(RuntimeException e){ public Result<String> runtimeException(RuntimeException e){
log.error("运行时异常:{}", e.getMessage()); log.error("运行时异常:", e);
if (e instanceof RRException){ if (e instanceof RRException){
RRException rrException = (RRException) e; RRException rrException = (RRException) e;
return Result.error(rrException.getCode(), rrException.getMsg()); return Result.error(rrException.getCode(), rrException.getMsg());
@ -111,7 +111,7 @@ public class ControllerAdvice {
*/ */
@ExceptionHandler(value = HttpRequestMethodNotSupportedException.class) @ExceptionHandler(value = HttpRequestMethodNotSupportedException.class)
public Result<String> httpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e){ public Result<String> httpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e){
log.warn("暂不支持该请求: {}", e.getMessage()); log.warn("暂不支持该请求: ", e);
return Result.error("暂不支持此请求方式"); return Result.error("暂不支持此请求方式");
} }
@ -121,7 +121,7 @@ public class ControllerAdvice {
*/ */
@ExceptionHandler(MethodArgumentTypeMismatchException.class) @ExceptionHandler(MethodArgumentTypeMismatchException.class)
public Result<String> methodArgument(MethodArgumentTypeMismatchException e){ public Result<String> methodArgument(MethodArgumentTypeMismatchException e){
log.warn("参数发生错误: {}", e.getMessage()); log.warn("参数发生错误: ", e);
return Result.error("参数发生错误"); return Result.error("参数发生错误");
} }
@ -132,7 +132,7 @@ public class ControllerAdvice {
*/ */
@ExceptionHandler(MissingServletRequestParameterException.class) @ExceptionHandler(MissingServletRequestParameterException.class)
public Result<String> exception(MissingServletRequestParameterException e){ public Result<String> exception(MissingServletRequestParameterException e){
log.warn("缺少请求参数: {}", e.getMessage()); log.warn("缺少请求参数: ", e);
return Result.error("缺少请求参数"); return Result.error("缺少请求参数");
} }

View File

@ -51,6 +51,13 @@ public class RegisterServiceImpl implements PrintService {
width = FIXED_WIDTH; width = FIXED_WIDTH;
} }
if ( StringUtils.isEmpty(printerConfig.getTimeType())){
throw new RRException("获取打印时间格式出错:" + printerConfig.getTimeType());
}
if ( StringUtils.isEmpty(printerConfig.getTerminalNumber())){
throw new RRException("获取终端号出错:" + printerConfig.getTerminalNumber());
}
// 强行设置终端号 // 强行设置终端号
data.put("terminalNumber", printerConfig.getTerminalNumber()); data.put("terminalNumber", printerConfig.getTerminalNumber());