package com.ard.common.core.exception.device;
|
|
/**
|
* SDK层设备异常基类(所有设备相关异常的父类)
|
*/
|
public class CameraSDKException extends RuntimeException {
|
// 异常码(标准化,方便前端/调用方识别)
|
private int code;
|
// 相机ID(定位具体异常设备)
|
private String cameraId;
|
|
public CameraSDKException(int code, String cameraId, String message) {
|
super(message);
|
this.code = code;
|
this.cameraId = cameraId;
|
}
|
|
// GETTER
|
public int getCode() { return code; }
|
public String getCameraId() { return cameraId; }
|
|
// 常用异常码枚举(标准化)
|
public enum ErrorCode {
|
CAMERA_NOT_EXIST(1001, "相机不存在"),
|
CAMERA_OFFLINE(1002, "相机离线"),
|
CHANNEL_NOT_EXIST(1003, "通道不存在"),
|
CMD_NOT_SUPPORT(1004, "相机不支持该指令"),
|
NETWORK_TIMEOUT(1005, "相机网络超时"),
|
AUTH_FAILED(1006, "相机登录认证失败"),
|
TCP_CONNECT_FAILED(1007, "tcp连接失败"),
|
OVER_GUIDANCE_RANGE(1008, "超出引导范围"),
|
BEYOND_VISIBILITY_RANGE(1009, "目标位于不可视域范围"),
|
CAMERA_MAX_VISIBLE_DISTANCE_NULL(1010,"相机最大可视距离为空");
|
|
private final int code;
|
private final String msg;
|
|
ErrorCode(int code, String msg) {
|
this.code = code;
|
this.msg = msg;
|
}
|
|
public int getCode() { return code; }
|
public String getMsg() { return msg; }
|
}
|
|
// 快捷创建异常的静态方法(简化开发)
|
public static CameraSDKException cameraNotExist(String cameraId) {
|
return new CameraSDKException(ErrorCode.CAMERA_NOT_EXIST.getCode(), cameraId,
|
ErrorCode.CAMERA_NOT_EXIST.getMsg() + ":" + cameraId);
|
}
|
|
public static CameraSDKException cameraOffline(String cameraId) {
|
return new CameraSDKException(ErrorCode.CAMERA_OFFLINE.getCode(), cameraId,
|
ErrorCode.CAMERA_OFFLINE.getMsg() + ":" + cameraId);
|
}
|
|
}
|