Browse Source

update CustomerRpcCodeException

MIke 2 years ago
parent
commit
a6cd044a70
2 changed files with 25 additions and 7 deletions
  1. 19 0
      Common/Exceptions/CustomerRpcCodeException.cs
  2. 6 7
      Service/DeviceService.cs

+ 19 - 0
Common/Exceptions/CustomerRpcCodeException.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Globalization;
+using WingInterfaceLibrary.Enum;
+using JsonRpcLite.Services;
+
+namespace WingDeviceService.Common
+{
+    /// <summary>
+    /// 自定义标识码
+    /// </summary>
+    public class CustomerRpcCodeException : RpcException
+    {
+        public CustomerRpcCodeException(CustomerRpcCode code):base((int)code,code.ToString() , null)
+        {
+            
+        }   
+    }
+
+}

+ 6 - 7
Service/DeviceService.cs

@@ -18,7 +18,6 @@ using WingInterfaceLibrary.DTO.User;
 using WingInterfaceLibrary.DTO.Management;
 using WingServerCommon.Config;
 using WingDeviceService.Common;
-using WingInterfaceLibrary.Enum.RpcExceptionEnum;
 using WingInterfaceLibrary.Request.User;
 using WingInterfaceLibrary.Enum;
 using WingInterfaceLibrary.DTO.Organization;
@@ -684,32 +683,32 @@ namespace WingDeviceService.Service
             var userCode = await ValidateTokenAsync(request.Token);
             if (string.IsNullOrEmpty(shortCode))
             {
-                throw new RpcException((int)DeviceErrorCodeEnum.UniqueCodeIsEmpty, "Unique code is empty", "Unique code is empty");
+                throw new CustomerRpcCodeException(CustomerRpcCode.UniqueCodeIsEmpty);
             }
             var device = await _deviceInfoDBServiceProxy.FindDeviceInfoByShortCodeAsync(shortCode);
             if (device == null)
             {
-                throw new RpcException((int)DeviceErrorCodeEnum.DeviceNotExist, "Device not exist", "Device not exist");
+                throw new NoExistDeviceException();
             }
             var oldOrg = await _organizationDBService.GetOrganizationDetailAsync(new GetOrganizationDBRequest { OrganizationCode = device.OrganizationCode });
             if (oldOrg == null || string.IsNullOrWhiteSpace(oldOrg.OrganizationCode))
             {
-                throw new RpcException((int)DeviceErrorCodeEnum.OrganizationNotExist, "Not exist device's organization ", "Not exist device's organization ");
+                throw new CustomerRpcCodeException(CustomerRpcCode.OrganizationNotExist);
             }
             //用户
             var userDTO = await _userServiceProxy.FindUserByCodeAsync(userCode);
             if (userDTO == null)
             {
-                throw new RpcException(1007, "user not exist", "user not exist");
+                throw new CustomerRpcCodeException(CustomerRpcCode.UserNotExistError);
             }
             if (!userDTO.IsDirector)
             {
-                throw new RpcException((int)DeviceErrorCodeEnum.NotOrgAdmin, "user not organization admin", "user not organization admin");
+                throw new CustomerRpcCodeException(CustomerRpcCode.NotOrgAdmin);
             }
             var org = await _organizationDBService.GetOrganizationDetailAsync(new GetOrganizationDBRequest { OrganizationCode = userDTO.OrganizationCode });
             if (org == null || string.IsNullOrWhiteSpace(org.OrganizationCode))
             {
-                throw new RpcException((int)DeviceErrorCodeEnum.OrganizationNotExist, "Not exist user's organization ", "Not exist user's organization ");
+                throw new CustomerRpcCodeException(CustomerRpcCode.OrganizationNotExist);
             }
             #endregion
             try