/// <summary> /// Log an specific error if it exists in response /// </summary> /// <param name="errorCode">errorcode for searching</param> public void LogAPIError(PostboxAPIErrorCode errorCode) { PostboxAPIError error = null; if (CheckErrorCode(errorCode, out error)) { PostboxLogbook.Instance.Log(error); } }
/// <summary> /// Check if an specific errorcode is in response and get error as return /// </summary> /// <param name="errorCode">errorcode for searching</param> /// <param name="error">the requested APIError</param> /// <returns>Boolean for error existens</returns> public bool CheckErrorCode(PostboxAPIErrorCode errorCode, out PostboxAPIError error) { if (Errors.TryGetValue(errorCode, out error)) { return(true); } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="PostboxResponse"/> class. /// </summary> /// <param name="localRequestId">local transaction identifier.</param> /// <param name="callName">callname of request</param> /// <param name="response">XmlDocument</param> public PostboxResponse(string localRequestId, PostboxCallName callName, XmlDocument response) { LocalRequestId = localRequestId; CallName = callName; XMLObject = response; if (response != null) { // PostboxGlobal-Node XmlNode postBoxGlobal = response.SelectSingleNode("PostBoxGlobal"); if (postBoxGlobal != null) { XmlNode callNamenNode = postBoxGlobal.SelectSingleNode("CallName"); CallName = CallNameStringToEnum(callNamenNode.InnerText); XmlNode callStatusNode = postBoxGlobal.SelectSingleNode("CallStatus"); CallStatus = CallStatusStringToEnum(callStatusNode.InnerText); XmlNode versionNode = postBoxGlobal.SelectSingleNode("Version"); Version = versionNode.InnerText; // Error-Node XmlNode errorList = postBoxGlobal.SelectSingleNode("ErrorList"); if (errorList != null) { XmlNodeList errorNodes = errorList.ChildNodes; if (errorNodes.Count > 0) { Errors = new Dictionary <PostboxAPIErrorCode, PostboxAPIError>(errorNodes.Count); for (int i = 0; i < errorNodes.Count; i++) { XmlNode errorCodeNode = errorNodes[i].SelectSingleNode("ErrorCode"); XmlNode errorDescriptionNode = errorNodes[i].SelectSingleNode("ErrorDescription"); XmlNode errorLongDescriptionNode = errorNodes[i].SelectSingleNode("ErrorLongDescription"); PostboxAPIError apiError = new PostboxAPIError(errorCodeNode.InnerText, errorDescriptionNode.InnerText, errorLongDescriptionNode.InnerText); Errors.Add(apiError.ErrorCode, apiError); } } } } } else { // If result is Empty CreateNoConnectionError(); } }
/// <summary> /// Initializes a new instance of the <see cref="PostboxResponse"/> class. /// </summary> /// <param name="localRequestId">local transaction identifier.</param> /// <param name="callName">callname of request</param> /// <param name="response">JSONObject</param> public PostboxResponse(string localRequestId, PostboxCallName callName, JSONObject response) { LocalRequestId = localRequestId; CallName = callName; JSONObject = response; if (response != null) { // PostboxGlobal-Node JSONObject postBoxGlobal = response; if (postBoxGlobal != null) { CallName = CallNameStringToEnum(postBoxGlobal.GetField("CallName").str); CallStatus = CallStatusStringToEnum(postBoxGlobal.GetField("CallStatus").str); Version = postBoxGlobal.GetField("Version").str; } // Error-Node JSONObject errorListNode = response.GetField("ErrorList"); if (errorListNode != null && errorListNode.IsArray) { List <JSONObject> errorList = errorListNode.list; if (errorList.Count > 0) { Errors = new Dictionary <PostboxAPIErrorCode, PostboxAPIError>(errorList.Count); for (int i = 0; i < errorList.Count; i++) { JSONObject error = errorList[i].GetField("Error"); if (error != null) { JSONObject errorCodeNode = error.GetField("ErrorCode"); JSONObject errorDescriptionNode = error.GetField("ErrorDescription"); JSONObject errorLongDescriptionNode = error.GetField("ErrorLongDescription"); PostboxAPIError apiError = new PostboxAPIError(errorCodeNode.i.ToString(), errorDescriptionNode.str, errorLongDescriptionNode.str); Errors.Add(apiError.ErrorCode, apiError); } } } } } else { // If result is Empty CreateNoConnectionError(); } }
/// <summary> /// Logging an APIError /// </summary> /// <param name="error">API Error Object of Response.Errors[]</param> /// <param name="level">Level of Notification (Notification, Warning, Error, APICalls)</param> public void Log(PostboxAPIError error, NotificationType level = NotificationType.Error) { this.Log(String.Format("[API-Error] {0} - {1}: {2}", error.ErrorCode, error.ErrorDescription, error.ErrorLongDescription), NotificationType.Error); }