Browse Source

location module business exception

pull/101/head
cKey 5 years ago
parent
commit
43f7894db2
  1. 4
      aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN/Abp/Location/Baidu/BaiduLocationHttpClient.cs
  2. 18
      aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN/Abp/Location/Baidu/Response/BaiduLocationResponse.cs
  3. 9
      aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN/Abp/Location/Tencent/Response/TencentLocationResponse.cs
  4. 2
      aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN/Abp/Location/Tencent/TencentLocationHttpClient.cs
  5. 28
      aspnet-core/modules/common/LINGYUN.Abp.Location/LINGYUN/Abp/Location/LocationResolveException.cs

4
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()) if (!baiduLocationResponse.IsSuccess())
{ {
var localizerFactory = ServiceProvider.GetRequiredService<IStringLocalizerFactory>(); var localizerFactory = ServiceProvider.GetRequiredService<IStringLocalizerFactory>();
var localizerErrorMessage = baiduLocationResponse.GetErrorMessage().Localize(localizerFactory); var localizerErrorMessage = baiduLocationResponse.GetErrorMessage(Options.VisableErrorToClient).Localize(localizerFactory);
var localizerErrorDescription = baiduLocationResponse.GetErrorMessage().Localize(localizerFactory); var localizerErrorDescription = baiduLocationResponse.GetErrorMessage(Options.VisableErrorToClient).Localize(localizerFactory);
var localizer = ServiceProvider.GetRequiredService<IStringLocalizer<BaiduLocationResource>>(); var localizer = ServiceProvider.GetRequiredService<IStringLocalizer<BaiduLocationResource>>();
localizerErrorMessage = localizer["ResolveLocationFailed", localizerErrorMessage, localizerErrorDescription]; localizerErrorMessage = localizer["ResolveLocationFailed", localizerErrorMessage, localizerErrorDescription];
if (Options.VisableErrorToClient) if (Options.VisableErrorToClient)

18
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; return Status == 0;
} }
public ILocalizableString GetErrorMessage() public ILocalizableString GetErrorMessage(bool throwToClient = false)
{ {
switch (Status) switch (Status)
{ {
@ -63,11 +63,16 @@ namespace LINGYUN.Abp.Location.Baidu.Response
return LocalizableString.Create<BaiduLocationResource>("Message:RETURN_401"); return LocalizableString.Create<BaiduLocationResource>("Message:RETURN_401");
case 402: case 402:
return LocalizableString.Create<BaiduLocationResource>("Message:RETURN_402"); return LocalizableString.Create<BaiduLocationResource>("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) switch (Status)
{ {
@ -117,7 +122,12 @@ namespace LINGYUN.Abp.Location.Baidu.Response
return LocalizableString.Create<BaiduLocationResource>("Description:RETURN_401"); return LocalizableString.Create<BaiduLocationResource>("Description:RETURN_401");
case 402: case 402:
return LocalizableString.Create<BaiduLocationResource>("Description:RETURN_402"); return LocalizableString.Create<BaiduLocationResource>("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!");
} }
} }
} }

9
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
/// </summary> /// </summary>
public bool IsSuccessed => Status.Equals(0); public bool IsSuccessed => Status.Equals(0);
public ILocalizableString GetErrorMessage() public ILocalizableString GetErrorMessage(bool throwToClient = false)
{ {
switch (Status) switch (Status)
{ {
@ -45,7 +45,12 @@ namespace LINGYUN.Abp.Location.Tencent.Response
return LocalizableString.Create<TencentLocationResource>("Message:RETURN_310"); return LocalizableString.Create<TencentLocationResource>("Message:RETURN_310");
case 311: case 311:
return LocalizableString.Create<TencentLocationResource>("Message:RETURN_311"); return LocalizableString.Create<TencentLocationResource>("Message:RETURN_311");
default: throw new AbpException(Message); default:
if (throwToClient)
{
throw new LocationResolveException(Message);
}
throw new AbpException(Message);
} }
} }
} }

2
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) if (Options.VisableErrorToClient)
{ {
var localizerFactory = ServiceProvider.GetRequiredService<IStringLocalizerFactory>(); var localizerFactory = ServiceProvider.GetRequiredService<IStringLocalizerFactory>();
var localizerErrorMessage = tencentLocationResponse.GetErrorMessage().Localize(localizerFactory); var localizerErrorMessage = tencentLocationResponse.GetErrorMessage(Options.VisableErrorToClient).Localize(localizerFactory);
var localizer = ServiceProvider.GetRequiredService<IStringLocalizer<TencentLocationResource>>(); var localizer = ServiceProvider.GetRequiredService<IStringLocalizer<TencentLocationResource>>();
localizerErrorMessage = localizer["ResolveLocationFailed", localizerErrorMessage]; localizerErrorMessage = localizer["ResolveLocationFailed", localizerErrorMessage];
throw new UserFriendlyException(localizerErrorMessage); throw new UserFriendlyException(localizerErrorMessage);

28
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)
{
}
}
}
Loading…
Cancel
Save