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 _errorDesc = new Dictionary(); static BaseApi() { //系统没有定义的错误代码 _errorDesc.Add("9999" , "响应的报文解析出现异常"); } protected static string PaserErrors(string response) { string result = string.Empty; try { _logger.Error(response); Errors mainError = JsonUtils.Deserialize(response); if (_errorDesc.ContainsKey(mainError.Code)) { result = _errorDesc[mainError.Code]; } else { result = mainError.Message; } List 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; } } }