Skip to content

Commit

Permalink
Throws an exception when API responses an error
Browse files Browse the repository at this point in the history
  • Loading branch information
gdlcf88 committed Mar 18, 2023
1 parent bd02889 commit b52ad7f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion common.props
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>1.3.3</Version>
<Version>1.4.0</Version>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>EasyAbp Team</Authors>
Expand Down
@@ -0,0 +1,12 @@
using Volo.Abp;

namespace EasyAbp.Abp.Sms.TencentCloud
{
public class FailedToSendSmsException : AbpException
{
public FailedToSendSmsException(string code, string message) : base(
$"Tencent Cloud API responses an error: [{code}] {message}.")
{
}
}
}
@@ -1,10 +1,11 @@
using System;
using Volo.Abp;

namespace EasyAbp.Abp.Sms.TencentCloud
{
public class InvalidTemplateParamSetException : ApplicationException
public class InvalidTemplateParamSetException : AbpException
{
public InvalidTemplateParamSetException() : base("TemplateParamSet should be IEnumerable<string>.")
public InvalidTemplateParamSetException() : base(
"TemplateParamSet should be IEnumerable<string> or JSON string collection.")
{
}
}
Expand Down
Expand Up @@ -52,8 +52,13 @@ await _settingProvider.GetOrNullAsync(AbpSmsTencentCloudSettings.DefaultSenderId
Region = await _settingProvider.GetOrNullAsync(AbpSmsTencentCloudSettings.DefaultRegion)
};

await _requester.SendRequestAsync<SendSmsResponse>(request,
var response = await _requester.SendRequestAsync<SendSmsResponse>(request,
await _settingProvider.GetOrNullAsync(AbpSmsTencentCloudSettings.EndPoint), commonOptions);

if (response.Error != null)
{
throw new FailedToSendSmsException(response.Error.Code, response.Error.Message);
}
}

protected virtual string GetStringProperty(SmsMessage smsMessage, string key, string defaultValue = null)
Expand Down

0 comments on commit b52ad7f

Please sign in to comment.