示例#1
0
 ///// <summary>
 ///// Initializes a new instance of the CloudStackException class.
 ///// </summary>
 ///// <param name="context">Description of problem.</param>
 ///// <param name="command">Details of command being executed at time of error.</param>
 ///// <param name="apiErrorResult">Error details from API.</param>
 ///// <param name="innerException">Exception causing problem.</param>
 //[SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "Need property to access underlying member variable")]
 public CloudStackException(string context, string command, APIErrorResult result, Exception innerException)
     : base(result.ErrorText, innerException)
 {
     this.Context     = context;
     this.Command     = string.IsNullOrEmpty(command) ? string.Empty : command;
     this.ErrorResult = result;
 }
 /// <summary>
 /// Create a CloudStackException from the supplied WebException. If avaiable the response
 /// stream is read and added to the exception.
 /// </summary>
 /// <param name="we">The WebException</param>
 /// <param name="fullUri">URI of the server</param>
 /// <returns>a CloudStackException</returns>
 private CloudStackBaseException CreateCloudStackException(WebException we, Uri fullUri)
 {
     if (we.InnerException is SocketException)
     {
         return(new CloudStackUnavailableException($"The CloudStack API Endpoint at {ServiceUrl} was unavailable", we.InnerException));
     }
     else if (we.Status == WebExceptionStatus.ProtocolError)
     {
         var responseStream = (HttpWebResponse)we.Response;
         try
         {
             using var reader = new StreamReader(responseStream.GetResponseStream());
             string         responseString = reader.ReadToEnd();
             APIErrorResult errorResult    = DecodeResponse <APIErrorResult>(responseString);
             return(new CloudStackException("ProtocolError on API Call", fullUri.ToString(), errorResult, we));
         }
         catch
         {
             return(new CloudStackException(
                        "Error on API call (cannot parse result)",
                        fullUri.ToString(),
                        responseStream.StatusCode.ToString(),
                        responseStream.StatusDescription,
                        we));
         }
     }
     return(new CloudStackException(
                "Error on API call",
                fullUri.ToString(),
                we.Status.ToString(),
                we.Message,
                we));
 }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the CloudStackException class.
 /// </summary>
 /// <param name="context">Description of problem.</param>
 /// <param name="command">Details of command being executed at time of error.</param>
 /// <param name="apiErrorResult">Error details from API.</param>
 public CloudStackException(string context, string command, APIErrorResult apiErrorResult)
     : this(context, command, apiErrorResult, null)
 {
 }