diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN/Abp/Location/Baidu/BaiduLocationHttpClient.cs b/aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN/Abp/Location/Baidu/BaiduLocationHttpClient.cs index e004494b7..f7f5864a7 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN/Abp/Location/Baidu/BaiduLocationHttpClient.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN/Abp/Location/Baidu/BaiduLocationHttpClient.cs @@ -67,8 +67,8 @@ namespace LINGYUN.Abp.Location.Baidu if (!baiduLocationResponse.IsSuccess()) { var localizerFactory = ServiceProvider.GetRequiredService(); - var localizerErrorMessage = baiduLocationResponse.GetErrorMessage().Localize(localizerFactory); - var localizerErrorDescription = baiduLocationResponse.GetErrorMessage().Localize(localizerFactory); + var localizerErrorMessage = baiduLocationResponse.GetErrorMessage(Options.VisableErrorToClient).Localize(localizerFactory); + var localizerErrorDescription = baiduLocationResponse.GetErrorMessage(Options.VisableErrorToClient).Localize(localizerFactory); var localizer = ServiceProvider.GetRequiredService>(); localizerErrorMessage = localizer["ResolveLocationFailed", localizerErrorMessage, localizerErrorDescription]; if (Options.VisableErrorToClient) diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN/Abp/Location/Baidu/Response/BaiduLocationResponse.cs b/aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN/Abp/Location/Baidu/Response/BaiduLocationResponse.cs index b0491d523..75fb189a2 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN/Abp/Location/Baidu/Response/BaiduLocationResponse.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN/Abp/Location/Baidu/Response/BaiduLocationResponse.cs @@ -13,7 +13,7 @@ namespace LINGYUN.Abp.Location.Baidu.Response return Status == 0; } - public ILocalizableString GetErrorMessage() + public ILocalizableString GetErrorMessage(bool throwToClient = false) { switch (Status) { @@ -63,11 +63,16 @@ namespace LINGYUN.Abp.Location.Baidu.Response return LocalizableString.Create("Message:RETURN_401"); case 402: return LocalizableString.Create("Message:RETURN_402"); - default: throw new AbpException($"{Status} - no error code define!"); + default: + if (throwToClient) + { + throw new LocationResolveException($"{Status} - no error code define!"); + } + throw new AbpException($"{Status} - no error code define!"); } } - public ILocalizableString GetErrorDescription() + public ILocalizableString GetErrorDescription(bool throwToClient = false) { switch (Status) { @@ -117,7 +122,12 @@ namespace LINGYUN.Abp.Location.Baidu.Response return LocalizableString.Create("Description:RETURN_401"); case 402: return LocalizableString.Create("Description:RETURN_402"); - default: throw new AbpException($"{Status} - no error code define!"); + default: + if (throwToClient) + { + throw new LocationResolveException($"{Status} - no error code define!"); + } + throw new AbpException($"{Status} - no error code define!"); } } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN/Abp/Location/Tencent/Response/TencentLocationResponse.cs b/aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN/Abp/Location/Tencent/Response/TencentLocationResponse.cs index da557ad2d..7885acf40 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN/Abp/Location/Tencent/Response/TencentLocationResponse.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN/Abp/Location/Tencent/Response/TencentLocationResponse.cs @@ -31,7 +31,7 @@ namespace LINGYUN.Abp.Location.Tencent.Response /// public bool IsSuccessed => Status.Equals(0); - public ILocalizableString GetErrorMessage() + public ILocalizableString GetErrorMessage(bool throwToClient = false) { switch (Status) { @@ -45,7 +45,12 @@ namespace LINGYUN.Abp.Location.Tencent.Response return LocalizableString.Create("Message:RETURN_310"); case 311: return LocalizableString.Create("Message:RETURN_311"); - default: throw new AbpException(Message); + default: + if (throwToClient) + { + throw new LocationResolveException(Message); + } + throw new AbpException(Message); } } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN/Abp/Location/Tencent/TencentLocationHttpClient.cs b/aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN/Abp/Location/Tencent/TencentLocationHttpClient.cs index 1fb2dddc2..c346d1403 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN/Abp/Location/Tencent/TencentLocationHttpClient.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN/Abp/Location/Tencent/TencentLocationHttpClient.cs @@ -184,7 +184,7 @@ namespace LINGYUN.Abp.Location.Tencent if (Options.VisableErrorToClient) { var localizerFactory = ServiceProvider.GetRequiredService(); - var localizerErrorMessage = tencentLocationResponse.GetErrorMessage().Localize(localizerFactory); + var localizerErrorMessage = tencentLocationResponse.GetErrorMessage(Options.VisableErrorToClient).Localize(localizerFactory); var localizer = ServiceProvider.GetRequiredService>(); localizerErrorMessage = localizer["ResolveLocationFailed", localizerErrorMessage]; throw new UserFriendlyException(localizerErrorMessage); diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Location/LINGYUN/Abp/Location/LocationResolveException.cs b/aspnet-core/modules/common/LINGYUN.Abp.Location/LINGYUN/Abp/Location/LocationResolveException.cs new file mode 100644 index 000000000..83c84ccc2 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.Location/LINGYUN/Abp/Location/LocationResolveException.cs @@ -0,0 +1,28 @@ +using System; +using System.Runtime.Serialization; +using Volo.Abp; + +namespace LINGYUN.Abp.Location +{ + public class LocationResolveException : AbpException, IBusinessException + { + public LocationResolveException() + { + } + + public LocationResolveException(string message) + : base(message) + { + } + + public LocationResolveException(string message, Exception innerException) + : base(message, innerException) + { + } + + public LocationResolveException(SerializationInfo serializationInfo, StreamingContext context) + : base(serializationInfo, context) + { + } + } +}