Ejemplo n.º 1
0
        public void RestResponseException_ConstructorsWithVariousParemeters_DoNotFail()
        {
            var restResponseException = new RestResponseException(System.Net.HttpStatusCode.BadRequest, new HttpRequestMessage(), "", new Exception());

            Assert.Equal(string.Empty, restResponseException.Body);
            Assert.Equal("[GET]", restResponseException.Message);

            var restResponseException2 = new RestResponseException(System.Net.HttpStatusCode.InternalServerError, new HttpRequestMessage(), null, "{}", new Exception());

            Assert.Equal("{}", restResponseException2.Body);
            Assert.Equal("[GET] {}", restResponseException2.Message);

            var restResponseException3 = new RestResponseException(System.Net.HttpStatusCode.BadRequest, new HttpRequestMessage(), "test", "{}");

            Assert.Equal("{}", restResponseException3.Body);
            Assert.Equal("[GET] test {}", restResponseException3.Message);

            var restResponseException4 = new RestResponseException(System.Net.HttpStatusCode.BadRequest, new HttpRequestMessage(HttpMethod.Post, @"http://localhost/"), "test", new Exception());

            Assert.Equal(string.Empty, restResponseException4.Body);
            Assert.Equal(@"[POST]http://localhost/ test", restResponseException4.Message);
        }
Ejemplo n.º 2
0
        private void ProcessImgurError(ImgurUploadErrorEventArgs e)
        {
            this.ToggleBusyIndicator(false);
            if (e.Exception != null && e.Exception.GetType() == typeof(RestResponseException))
            {
                RestResponseException ex = e.Exception as RestResponseException;
                ModalDialog._logger.ErrorException("Processing Imgur error exception", ex);
                string str = string.Empty;
                if (ex.Response == null)
                {
                    str = ex.Message;
                }
                else
                {
                    if (ex.Response.ErrorException != null)
                    {
                        str = ex.Response.ErrorMessage;
                    }
                    else
                    {
                        JsonDeserializer     jsonDeserializer     = new JsonDeserializer();
                        MashapeErrorResponse mashapeErrorResponse = jsonDeserializer.Deserialize <MashapeErrorResponse>(ex.Response);
                        str = mashapeErrorResponse.Message;
                    }
                }
                string message         = LocalizationProvider.GetLocalizedString("Error_UploadingImageToImgurMessage", false, "MarkdownPadStrings") + StringUtilities.GetNewLines(2) + str;
                string localizedString = LocalizationProvider.GetLocalizedString("Error_UploadingImageToImgur", false, "MarkdownPadStrings");
                MessageBoxHelper.ShowWarningMessageBox(message, localizedString);
                return;
            }
            System.Exception exception        = e.Exception;
            string           localizedString2 = LocalizationProvider.GetLocalizedString("Error_UploadingImageToImgurMessage", false, "MarkdownPadStrings");
            string           localizedString3 = LocalizationProvider.GetLocalizedString("Error_UploadingImageToImgur", false, "MarkdownPadStrings");

            MessageBoxHelper.ShowErrorMessageBox(localizedString2, localizedString3, exception, "");
        }