You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.7 KiB
C#

9 months ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using POSV.Utils;
namespace POSV.HttpApi
{
public abstract class BaseApi
{
protected static NLog.Logger _logger = NLog.LogManager.GetCurrentClassLogger();
protected static Dictionary<string , string> _errorDesc = new Dictionary<string , string>();
static BaseApi()
{
//系统没有定义的错误代码
_errorDesc.Add("9999" , "响应的报文解析出现异常");
}
protected static string PaserErrors(string response)
{
string result = string.Empty;
try
{
_logger.Error(response);
Errors mainError = JsonUtils.Deserialize<Errors>(response);
if (_errorDesc.ContainsKey(mainError.Code))
{
result = _errorDesc[mainError.Code];
}
else
{
result = mainError.Message;
}
List<SubErrors> subError = mainError.SubErrors;
if (subError != null && subError.Count > 0)
{
SubErrors error = subError[0];
if (_errorDesc.ContainsKey(error.Code))
{
result = _errorDesc[error.Code];
}
else
{
result = error.Message;
}
}
}
catch (Exception ex)
{
_logger.Error(ex , "非法的错误信息格式");
result = _errorDesc["9999"];
}
return result;
}
}
}