Esempio n. 1
1
        /// <summary>
        /// Initializes a new instance of the <see cref="ClientException"/> class.
        /// </summary>
        /// <param name="message">The corresponding error message.</param>
        /// <param name="httpStatus">The Http Status code.</param>
        public ClientException(string message, HttpStatusCode httpStatus)
            : base(message)
        {
            HttpStatus = httpStatus;

            Error = new ClientError()
            {
                Code = HttpStatus.ToString(),
                Message = message
            };
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClientException"/> class.
 /// </summary>
 /// <param name="message">The corresponding error message.</param>
 /// <param name="innerException">The inner exception.</param>
 public ClientException(string message, Exception innerException)
     : base(message, innerException)
 {
     Error = new ClientError()
     {
         Code = HttpStatusCode.InternalServerError.ToString(),
         Message = message
     };
 }
Esempio n. 3
0
        /// <summary>
        /// Process the exception happened on rest call.
        /// </summary>
        /// <param name="exception">Exception object.</param>
        private void HandleException(Exception exception)
        {
            WebException webException = exception as WebException;

            if (webException != null && webException.Response != null)
            {
                if (webException.Response.ContentType.ToLower().Contains("application/json"))
                {
                    Stream stream = null;

                    try
                    {
                        stream = webException.Response.GetResponseStream();
                        if (stream != null)
                        {
                            string errorObjectString;
                            using (StreamReader reader = new StreamReader(stream))
                            {
                                stream            = null;
                                errorObjectString = reader.ReadToEnd();
                            }

                            ClientError errorCollection = JsonConvert.DeserializeObject <ClientError>(errorObjectString);
                            if (errorCollection != null)
                            {
                                throw new ClientException
                                      {
                                          Error = errorCollection
                                      };
                            }
                        }
                    }
                    finally
                    {
                        if (stream != null)
                        {
                            stream.Dispose();
                        }
                    }
                }
            }

            throw exception;
        }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClientException"/> class.
 /// </summary>
 /// <param name="error">The error entity.</param>
 /// <param name="httpStatus">The http status.</param>
 public ClientException(ClientError error, HttpStatusCode httpStatus)
 {
     Error = error;
     HttpStatus = httpStatus;
 }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClientException"/> class.
        /// </summary>
        /// <param name="message">The corresponding error message.</param>
        /// <param name="errorCode">The error code.</param>
        /// <param name="httpStatus">The http status.</param>
        /// <param name="innerException">The inner exception.</param>
        public ClientException(string message, string errorCode, HttpStatusCode httpStatus, Exception innerException)
            : base(message, innerException)
        {
            HttpStatus = httpStatus;

            Error = new ClientError()
            {
                Code = errorCode,
                Message = message
            };
        }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClientException"/> class.
 /// </summary>
 /// <param name="error">The error entity.</param>
 /// <param name="httpStatus">The http status.</param>
 public ClientException(ClientError error, HttpStatusCode httpStatus)
 {
     this.Error      = error;
     this.HttpStatus = httpStatus;
 }
Esempio n. 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClientException"/> class.
 /// </summary>
 /// <param name="error">The error entity.</param>
 /// <param name="httpStatus">The http status.</param>
 public ClientException(ClientError error, HttpStatusCode httpStatus)
 {
     this.Error = error;
     this.HttpStatus = httpStatus;
 }