Browse Source

错误码1001

Jeremy 2 years ago
parent
commit
913e414892
2 changed files with 18 additions and 31 deletions
  1. 11 17
      Service/ConnectService.cs
  2. 7 14
      Service/DeviceService.cs

+ 11 - 17
Service/ConnectService.cs

@@ -38,31 +38,31 @@ namespace WingDeviceService.Service
 
                 if (string.IsNullOrWhiteSpace(request.DeviceUniqueCode))
                 {
-                    throw new RpcException(1001, "DeviceUniqueCode empty error", "DeviceUniqueCode empty error");
+                    throw new RpcException((int)CustomerRpcCode.DeviceUniqueCodeEmpty, "DeviceUniqueCode empty error", "DeviceUniqueCode empty error");
                 }
                 if (string.IsNullOrWhiteSpace(request.DeviceModel))
                 {
-                    throw new RpcException(1001, "DeviceModel empty error", "DeviceModel empty error");
+                    throw new RpcException((int)CustomerRpcCode.DeviceModelEmpty, "DeviceModel empty error", "DeviceModel empty error");
                 }
                 if (string.IsNullOrWhiteSpace(request.DeviceType))
                 {
-                    throw new RpcException(1001, "DeviceType empty error", "DeviceType empty error");
+                    throw new RpcException((int)CustomerRpcCode.DeviceTypeEmpty, "DeviceType empty error", "DeviceType empty error");
                 }
                 if (string.IsNullOrWhiteSpace(request.SoftwareVersion))
                 {
-                    throw new RpcException(1001, "SoftwareVersion empty error", "SoftwareVersion empty error");
+                    throw new RpcException((int)CustomerRpcCode.SoftwareVersionEmpty, "SoftwareVersion empty error", "SoftwareVersion empty error");
                 }
                 if (string.IsNullOrWhiteSpace(request.SystemVersion))
                 {
-                    throw new RpcException(1001, "SystemVersion empty error", "SystemVersion empty error");
+                    throw new RpcException((int)CustomerRpcCode.SystemVersionEmpty, "SystemVersion empty error", "SystemVersion empty error");
                 }
                 if (string.IsNullOrWhiteSpace(request.CPUModel))
                 {
-                    throw new RpcException(1001, "CPUModel empty error", "CPUModel empty error");
+                    throw new RpcException((int)CustomerRpcCode.CPUModelEmpty, "CPUModel empty error", "CPUModel empty error");
                 }
                 if (string.IsNullOrWhiteSpace(request.SystemLanguage))
                 {
-                    throw new RpcException(1001, "SystemLanguage empty error", "SystemLanguage empty error");
+                    throw new RpcException((int)CustomerRpcCode.SystemVersionEmpty, "SystemLanguage empty error", "SystemLanguage empty error");
                 }
 
                 #endregion
@@ -137,13 +137,10 @@ namespace WingDeviceService.Service
                     UniqueCode = shortCode
                 };
             }
-            catch (RpcException)
-            {
-                throw;
-            }
             catch (Exception ex)
             {
-                throw new RpcException(1001, ex.Message, ex.InnerException?.Message);
+                Logger.WriteLineWarn($"device connect server failed, err:{ex}");
+                throw;
             }
         }
 
@@ -173,13 +170,10 @@ namespace WingDeviceService.Service
                 await _authenticationService.LogOffAsync(request);
                 return true;
             }
-            catch (RpcException)
-            {
-                throw;
-            }
             catch (Exception ex)
             {
-                throw new RpcException(1001, ex.Message, ex.InnerException?.Message);
+                Logger.WriteLineWarn($"device disconnect failed, ex:{ex}");
+                throw;
             }
         }
 

+ 7 - 14
Service/DeviceService.cs

@@ -139,7 +139,7 @@ namespace WingDeviceService.Service
             await ValidateTokenAsync(request.Token);
             if (string.IsNullOrWhiteSpace(request.DeviceCode))
             {
-                throw new RpcException(1001, "DeviceCode empty error", "DeviceCode empty error");
+                throw new RpcException((int)CustomerRpcCode.DeviceCodeEmpty, "DeviceCode empty error", "DeviceCode empty error");
             }
             var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(request.DeviceCode);
             if (deviceDb == null || deviceDb.DeviceCode != request.DeviceCode)
@@ -193,7 +193,7 @@ namespace WingDeviceService.Service
             await ValidateTokenAsync(request.Token);
             if (string.IsNullOrWhiteSpace(request.ShortCode))
             {
-                throw new RpcException(1001, "ShortCode empty error", "ShortCode empty error");
+                throw new RpcException((int)CustomerRpcCode.ShortCodeEmpty, "ShortCode empty error", "ShortCode empty error");
             }
             var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByShortCodeAsync(request.ShortCode);
             if (deviceDb == null || deviceDb.ShortCode != request.ShortCode)
@@ -271,20 +271,13 @@ namespace WingDeviceService.Service
             await ValidateTokenAsync(request.Token);
             if (string.IsNullOrWhiteSpace(request.DeviceCode) || string.IsNullOrWhiteSpace(request.OrganizationCode))
             {
-                throw new RpcException(1001, "DeviceCode Or OrganizationCode empty error", "DeviceCode Or OrganizationCode empty error");
+                throw new RpcException((int)CustomerRpcCode.DeviceCodeOrOrganizationCodeEmpty, "DeviceCode Or OrganizationCode empty error", "DeviceCode Or OrganizationCode empty error");
             }
             var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(request.DeviceCode);
             if (deviceDb == null || deviceDb.OrganizationCode != request.OrganizationCode || deviceDb.DepartmentCode != request.DepartmentCode)
             {
-                throw new RpcException(1001, "DeviceInfo not exist error", "DeviceInfo not exist error");
+                throw new RpcException((int)CustomerRpcCode.DeviceNotExist, "DeviceInfo not exist error", "DeviceInfo not exist error");
             }
-            // //根据机构code和设备code去用户表查询关联数据,如果有则返回异常,否则就解除绑定关系;
-            // var isExistUserRelevancy = false;
-            // //todo 到时候调用mike的关联用户接口
-            // if (isExistUserRelevancy)
-            // {
-            //     throw new RpcException(1001, "This Device Exist Share User error", "This Device Exist Share User error");
-            // }
             //根据设备code和机构code查询相关数据,查到则删除关联
             if (!string.IsNullOrEmpty(deviceDb.DepartmentCode))
             {
@@ -395,7 +388,7 @@ namespace WingDeviceService.Service
             var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByShortCodeAsync(request.ShortCode);
             if (deviceDb == null)
             {
-                throw new RpcException(1001, "Not find device", "Not find device");
+                throw new RpcException((int)CustomerRpcCode.DeviceNotExist, "Not find device", "Not find device");
             }
             if (userInfoDO.BindDevices != null && userInfoDO.BindDevices.Contains(deviceDb.DeviceCode))
             {
@@ -463,11 +456,11 @@ namespace WingDeviceService.Service
             var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(request.DeviceCode);
             if (deviceDb == null)
             {
-                throw new RpcException(1001, "Not find device", "Not find device");
+                throw new RpcException((int)CustomerRpcCode.DeviceNotExist, "Not find device", "Not find device");
             }
             if (string.IsNullOrWhiteSpace(request.Name))
             {
-                throw new RpcException(1001, "Device name cannot be empty", "Device name cannot be empty");
+                throw new RpcException((int)CustomerRpcCode.DeviceNameEmpty, "Device name cannot be empty", "Device name cannot be empty");
             }
             deviceDb.Name = request.Name;
             if (!string.IsNullOrWhiteSpace(request.HeadPicUrl))