Esempio n. 1
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. 2
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. 3
0
        /// <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. 4
0
        /// <summary>
        /// Process the exception happened on rest call.
        /// </summary>
        /// <param name="exception">Exception object.</param>
        private void HandleException(Exception exception)
        {
            if (exception is WebException webException && webException.Response != null && 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);

                        // HandwritingOcr error message use the latest format, so add the logic to handle this issue.
                        if (errorCollection.Code == null && errorCollection.Message == null)
                        {
                            var errorType = new { Error = new ClientError() };
                            var errorObj  = JsonConvert.DeserializeAnonymousType(errorObjectString, errorType);
                            errorCollection = errorObj.Error;
                        }

                        if (errorCollection != null)
                        {
                            throw new ClientException
                                  {
                                      Error = errorCollection,
                                  };
                        }
                    }
                }
                finally
                {
                    if (stream != null)
                    {
                        stream.Dispose();
                    }
                }
            }

            throw exception;
        }
Esempio n. 5
0
 public ClientException(HttpStatusCode httpStatus, ClientError error)
 {
     HttpStatus = httpStatus;
     Error      = error;
 }
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)
 {
     Error      = error;
     HttpStatus = httpStatus;
 }