Toast Ignore Empty

This commit is contained in:
Aigio Liu
2021-10-03 14:52:46 +08:00
parent c06398acf8
commit 563d218341
2 changed files with 22 additions and 19 deletions
@@ -31,6 +31,8 @@ namespace System.Application.Services.Implementation
public void Show(string text, int? duration)
{
if (string.IsNullOrEmpty(text)) return;
try
{
if (IsMainThread)
@@ -54,9 +54,19 @@ namespace System.Application.Models
return response.IsSuccess && content != null;
}
static bool IsClientExceptionOrServerException(ApiResponseCode code) => code switch
{
ApiResponseCode.ClientException => true,
_ => false,
};
public static string GetMessage(this ApiResponseCode code, string? errorAppendText = null, string? errorFormat = null)
{
if (code == ApiResponseCode.Unauthorized)
if (code == ApiResponseCode.OK)
{
return string.Empty;
}
else if (code == ApiResponseCode.Unauthorized)
{
return SR.ApiResponseCode_Unauthorized;
}
@@ -72,35 +82,26 @@ namespace System.Application.Models
{
return Const.UserIsBanErrorMessage;
}
static bool IsClientExceptionOrServerException(ApiResponseCode code) => code switch
{
ApiResponseCode.ClientException => true,
_ => false,
};
string message;
var notErrorAppendText = string.IsNullOrWhiteSpace(errorAppendText);
if (string.IsNullOrWhiteSpace(errorFormat))
{
if (string.IsNullOrWhiteSpace(errorAppendText))
if (notErrorAppendText)
{
message = IsClientExceptionOrServerException(code) ? SR.ClientError_ : SR.ServerError_;
message = message.Format((int)code);
errorFormat = IsClientExceptionOrServerException(code) ? SR.ClientError_ : SR.ServerError_;
}
else
{
message = IsClientExceptionOrServerException(code) ? SR.ClientError__ : SR.ServerError__;
message = message.Format((int)code, errorAppendText);
errorFormat = IsClientExceptionOrServerException(code) ? SR.ClientError__ : SR.ServerError__;
}
}
if (notErrorAppendText)
{
message = errorFormat.Format((int)code);
}
else
{
if (string.IsNullOrWhiteSpace(errorAppendText))
{
message = errorFormat.Format((int)code);
}
else
{
message = errorFormat.Format((int)code, errorAppendText);
}
message = errorFormat.Format((int)code, errorAppendText);
}
return message;
}