ExtendException.cs
4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
namespace Rcs.Domain.Extensions
{
/// <summary>
/// 通用业务异常扩展集
/// </summary>
public class BusinessException : Exception
{
public int ErrorCode { get; set; }
public BusinessException(string message, int errorCode = 0)
: base(message)
{
ErrorCode = errorCode;
}
}
/// <summary>
/// 通用异常扩展集
/// </summary>
public class SharedException : Exception
{
public int Code { get; }
/// <summary>
///
/// </summary>
/// <param name="robotId"></param>
/// <param name="code"></param>
/// <param name="message"></param>
public SharedException(int code, string message = "")
: base($"错误代码[{code}] - {GetMessage(code)} {message}")
{
Code = code;
}
private static string GetMessage(int code)
{
return code switch
{
10000 => "入参不正确",
10001 => "消息格式不正确",
10002 => "消息已过期",
_ => $"未知错误"
};
}
}
/// <summary>
/// 机器人异常扩展集
/// </summary>
public class ExtendRobotException : Exception
{
public string RobotId { get; }
public int Code { get; }
/// <summary>
///
/// </summary>
/// <param name="robotId"></param>
/// <param name="code"></param>
/// <param name="message"></param>
public ExtendRobotException(string robotId, int code, string message = "")
: base($"错误代码[{code}] - 机器人 {robotId} : {GetMessage(code)} {message}")
{
RobotId = robotId;
Code = code;
}
private static string GetMessage(int code)
{
return code switch
{
20000 => "机器人离线",
20001 => "机器人路径锁死",
20002 => "机器人上线失败",
20003 => "不存在机器人",
20004 => "机器人无法定位",
20005 => "机器人不在拓扑点位",
_ => $"未知机器人错误"
};
}
}
public class ExtendTaskException : Exception
{
public string TaskId { get; }
public int Code { get; }
/// <summary>
///
/// </summary>
/// <param name="robotId"></param>
/// <param name="code"></param>
public ExtendTaskException(string taskId, int code, string message = "")
: base($"错误代码[{code}] - 任务 {taskId} : {GetMessage(code)} {message}")
{
TaskId = taskId;
Code = code;
}
private static string GetMessage(int code)
{
return code switch
{
30000 => "相同起点和终点任务已存在",
30001 => "路径规划失败",
30002 => "路径不可达",
30003 => "起点和终点位置相同",
30004 => "任务不存在",
30005 => "任务已取消",
30006 => "任务已完成",
30007 => "任务执行中,无法取消",
30008 => "任务未分配,无法取消",
30009 => "任务未开始,无法暂停",
30010 => "任务未暂停,无法恢复",
30011 => "任务未暂停,无法取消",
30012 => "起始位置不存在",
30013 => "目标位置不存在",
_ => "未知任务错误"
};
}
}
public class ExtendModelException : Exception
{
public string TaskId { get; }
public long Code { get; }
/// <summary>
///
/// </summary>
/// <param name="robotId"></param>
/// <param name="code"></param>
public ExtendModelException(string modelId, long code, string message = "")
: base($"错误代码[{code}] - 模型 {modelId} : {GetMessage(code)} {message}")
{
TaskId = modelId;
Code = code;
}
private static string GetMessage(long code)
{
return code switch
{
40000 => "地图数据不存在",
_ => "未知任务错误"
};
}
}
}