コード例 #1
18
ファイル: ExceptionHelper.cs プロジェクト: limufan/EIM
        public static EIMException CreateException(Exception ex)
        {
            EIMException eimException = null;

            if (ex is WebServiceException)
            {
                WebServiceException webServiceException = ex as WebServiceException;
                Type exceptionType = Type.GetType(webServiceException.ErrorCode);
                eimException = Activator.CreateInstance(exceptionType, webServiceException.ErrorMessage) as EIMException;

                return(eimException);
            }

            if (eimException)
            {
                return(eimException);
            }
        }
コード例 #2
0
		public void Can_retrieve_empty_Errors_from_Dto_NoStatusResponse()
		{
			var webEx = new WebServiceException
			{
				ResponseDto = new NoStatusResponse()
			};

			Assert.That(webEx.ErrorCode, Is.Null);
			Assert.That(webEx.ErrorMessage, Is.Null);
			Assert.That(webEx.ServerStackTrace, Is.Null);
		}
コード例 #3
0
	    public void Can_Retrieve_Errors_From_ResponseBody_If_ResponseDto_Does_Not_Contain_ResponseStatus()
	    {
	        var webEx = new WebServiceException
	            {
	                ResponseDto = new List<string> {"123"},
	                ResponseBody = "{\"ResponseStatus\":" +
	                               "{\"ErrorCode\":\"UnauthorizedAccessException\"," +
	                               "\"Message\":\"Error Message\"," +
	                               "\"StackTrace\":\"Some Stack Trace\",\"Errors\":[]}}"
	            };
	        Assert.That(webEx.ErrorCode, Is.EqualTo("UnauthorizedAccessException"));
            Assert.That(webEx.ErrorMessage, Is.EqualTo("Error Message"));
            Assert.That(webEx.ServerStackTrace, Is.EqualTo("Some Stack Trace"));
	    }
コード例 #4
0
        public static SamplesApiException CreateSamplesApiExceptionFromResponse(WebServiceException e)
        {
            if (e.ResponseHeaders["server"] == "AmazonS3")
            {
                return(new SamplesMaintenanceModeException($"{e.Message}: AQUARIUS Samples is in maintenance mode", e));
            }

            var errorResponse = DeserializeErrorFromResponse(e);
            var message       = ComposeMessage(e, errorResponse);

            if (errorResponse?.ErrorCode == "gaia.domain.exceptions.AuthenticationException")
            {
                return(new SamplesAuthenticationException(message, e, errorResponse));
            }

            return(new SamplesApiException(message, e, errorResponse));
        }
コード例 #5
0
        public void Can_Retrieve_Errors_From_ResponseBody_If_ResponseDto_Does_Not_Contain_ResponseStatus()
        {
            var webEx = new WebServiceException
            {
                ResponseDto = new List <string> {
                    "123"
                },
                ResponseBody = "{\"ResponseStatus\":" +
                               "{\"ErrorCode\":\"UnauthorizedAccessException\"," +
                               "\"Message\":\"Error Message\"," +
                               "\"StackTrace\":\"Some Stack Trace\",\"Errors\":[]}}"
            };

            Assert.That(webEx.ErrorCode, Is.EqualTo("UnauthorizedAccessException"));
            Assert.That(webEx.ErrorMessage, Is.EqualTo("Error Message"));
            Assert.That(webEx.ServerStackTrace, Is.EqualTo("Some Stack Trace"));
        }
コード例 #6
0
        public void GET_returns_ArgumentNullException()
        {
            var restClient = CreateRestClient();

            WebServiceException webEx    = null;
            HttpErrorResponse   response = null;

            restClient.GetAsync <HttpErrorResponse>(ListeningOn + "errors",
                                                    r => response = r,
                                                    (r, ex) => {
                response = r;
                webEx    = (WebServiceException)ex;
            });

            Thread.Sleep(1000);

            Assert.That(webEx.StatusCode, Is.EqualTo(400));
            Assert.That(response.ResponseStatus.ErrorCode, Is.EqualTo(typeof(ArgumentNullException).Name));
        }
コード例 #7
0
        public void Can_retrieve_Errors_from_Dto_WithStatusResponse()
        {
            var webEx = new WebServiceException
            {
                ResponseDto = new WithStatusResponse
                {
                    ResponseStatus = new ResponseStatus
                    {
                        ErrorCode  = "errorCode",
                        Message    = "errorMessage",
                        StackTrace = "stackTrace"
                    }
                }
            };

            Assert.That(webEx.ErrorCode, Is.EqualTo("errorCode"));
            Assert.That(webEx.ErrorMessage, Is.EqualTo("errorMessage"));
            Assert.That(webEx.ServerStackTrace, Is.EqualTo("stackTrace"));
        }
コード例 #8
0
		public void Can_retrieve_Errors_from_Dto_WithStatusResponse()
		{
			var webEx = new WebServiceException
			{
				ResponseDto = new WithStatusResponse
				{
					ResponseStatus = new ResponseStatus
					{
						ErrorCode = "errorCode",
						Message = "errorMessage",
						StackTrace = "stackTrace"
					}
				}
			};

			Assert.That(webEx.ErrorCode, Is.EqualTo("errorCode"));
			Assert.That(webEx.ErrorMessage, Is.EqualTo("errorMessage"));
			Assert.That(webEx.ServerStackTrace, Is.EqualTo("stackTrace"));
		}
コード例 #9
0
        public void GET_returns_custom_Exception_and_StatusCode()
        {
            var restClient = CreateRestClient();

            WebServiceException webEx    = null;
            HttpErrorResponse   response = null;

            restClient.GetAsync <HttpErrorResponse>(ListeningOn + "errors/FileNotFoundException/404",
                                                    r => response = r,
                                                    (r, ex) =>
            {
                response = r;
                webEx    = (WebServiceException)ex;
            });

            Thread.Sleep(1000);

            Assert.That(webEx.StatusCode, Is.EqualTo(404));
            Assert.That(response.ResponseStatus.ErrorCode, Is.EqualTo(typeof(FileNotFoundException).Name));
        }
コード例 #10
0
            private static void HandleException <TResponse>(Exception exception, Action <TResponse, Exception> onError)
            {
                var response          = (TResponse)typeof(TResponse).CreateInstance();
                var hasResponseStatus = response as IHasResponseStatus;

                if (hasResponseStatus != null)
                {
                    hasResponseStatus.ResponseStatus = new ResponseStatus {
                        ErrorCode  = exception.GetType().Name,
                        Message    = exception.Message,
                        StackTrace = exception.StackTrace,
                    };
                }
                var webServiceEx = new WebServiceException(exception.Message, exception);

                if (onError != null)
                {
                    onError(response, webServiceEx);
                }
            }
コード例 #11
0
            internal static TRes MakeApiRequest <TReq, TRes>(
                Uri endpoint, HttpMethod httpMethod, TReq body, string actionDescription, string apiKey)
            {
                try
                {
                    HttpWebRequest request = CreateWebRequest <TReq>(
                        endpoint, httpMethod, body, apiKey);

                    return(GetResponse <TRes>(request));
                }
                catch (WebException ex)
                {
                    throw WebServiceException.AdaptException(ex, actionDescription, endpoint);
                }
                catch (Exception ex)
                {
                    ExceptionLogger.LogException(actionDescription, ex.Message, ex.StackTrace, endpoint, HttpStatusCode.OK);
                    throw;
                }
            }
コード例 #12
0
        public override object OnServiceException(ServiceStack.Web.IRequest httpReq, object request, Exception ex)
        {
            if (ex != null)
            {
                string errorMessage = ex.Message;
                string rawUrl       = "";
                if (httpReq != null)
                {
                    rawUrl = httpReq.RawUrl;
                }

                if (ex is WebServiceException)
                {
                    WebServiceException webServiceException = ex as WebServiceException;
                    errorMessage = webServiceException.ErrorMessage;
                }
                if (request != null)
                {
                    errorMessage = string.Format("Post 出错{0}, requestType: {1}, request: {2}, rawUrl: {3}",
                                                 errorMessage,
                                                 request.GetType().Name,
                                                 JsonConvert.SerializeObject(request),
                                                 rawUrl);
                }

                if (ex is ValidateException)
                {
                    EIMLog.Logger.Info(errorMessage, ex);
                }
                else
                {
                    EIMLog.Logger.Error(errorMessage, ex);
                }
            }
            else
            {
                EIMLog.Logger.Error(request);
            }

            return(base.OnServiceException(httpReq, request, ex));
        }
コード例 #13
0
            public TResponse Send <TResponse>(object request)
            {
                var response   = ServiceManager.Execute(request);
                var httpResult = response as IHttpResult;

                if (httpResult != null)
                {
                    if (httpResult.StatusCode >= HttpStatusCode.BadRequest)
                    {
                        var webEx = new WebServiceException(httpResult.StatusDescription)
                        {
                            ResponseDto = httpResult.Response,
                            StatusCode  = httpResult.Status,
                        };
                        throw webEx;
                    }
                    return((TResponse)httpResult.Response);
                }

                return((TResponse)response);
            }
コード例 #14
0
        public void DELETE_a_non_existing_file_throws_404()
        {
            var restClient = CreateAsyncRestClient();

            WebServiceException webEx    = null;
            FilesResponse       response = null;

            restClient.DeleteAsync <FilesResponse>("files/non-existing-file.txt",
                                                   r => response = r,
                                                   (r, ex) =>
            {
                response = r;
                webEx    = (WebServiceException)ex;
            });

            Thread.Sleep(1000);

            Assert.That(webEx.StatusCode, Is.EqualTo(404));
            Assert.That(response.ResponseStatus.ErrorCode, Is.EqualTo(typeof(FileNotFoundException).Name));
            Assert.That(response.ResponseStatus.Message, Is.EqualTo("Could not find: non-existing-file.txt"));
        }
コード例 #15
0
        public void GET_a_file_that_doesnt_exist_throws_a_404_FileNotFoundException()
        {
            var restClient = CreateAsyncRestClient();

            WebServiceException webEx    = null;
            FilesResponse       response = null;

            restClient.GetAsync <FilesResponse>("files/UnknownFolder",
                                                r => response = r,
                                                (r, ex) =>
            {
                response = r;
                webEx    = (WebServiceException)ex;
            });

            Thread.Sleep(1000);

            Assert.That(webEx.StatusCode, Is.EqualTo(404));
            Assert.That(response.ResponseStatus.ErrorCode, Is.EqualTo(typeof(FileNotFoundException).Name));
            Assert.That(response.ResponseStatus.Message, Is.EqualTo("Could not find: UnknownFolder"));
        }
コード例 #16
0
        private static void AssertErrorResponse(WebServiceException ex)
        {
            Assert.That(ex.ErrorCode, Is.EqualTo("NotNull"));
            Assert.That(ex.ErrorMessage, Is.EqualTo("'First Name' must not be empty."));
            var status = ex.ResponseStatus;

            Assert.That(status.Errors.Count, Is.EqualTo(3));

            var fieldError = status.Errors.First(x => x.FieldName == nameof(RockstarBase.FirstName));

            Assert.That(fieldError.ErrorCode, Is.EqualTo("NotNull"));
            Assert.That(fieldError.Message, Is.EqualTo("'First Name' must not be empty."));

            fieldError = status.Errors.First(x => x.FieldName == nameof(RockstarBase.Age));
            Assert.That(fieldError.ErrorCode, Is.EqualTo("NotNull"));
            Assert.That(fieldError.Message, Is.EqualTo("'Age' must not be empty."));

            fieldError = status.Errors.First(x => x.FieldName == nameof(RockstarBase.LastName));
            Assert.That(fieldError.ErrorCode, Is.EqualTo("NotNull"));
            Assert.That(fieldError.Message, Is.EqualTo("'Last Name' must not be empty."));
        }
コード例 #17
0
        public BaseSpaceException(string message, string errorCode, Exception ex)
            : base(message, ex)
        {
            StatusCode = (HttpStatusCode)RetryLogic.GetStatusCode(ex);
            ErrorCode  = errorCode;
            WebServiceException wse = ex as WebServiceException;

            if (wse != null)
            {
                Response = wse.ResponseDto as IHasResponseStatus;
                if (wse.ResponseBody != null)
                {
                    try
                    {
                        ResponseBodyJson = JsonObject.Parse(wse.ResponseBody);
                    }
                    catch
                    {
                    }
                }
            }
        }
コード例 #18
0
        public static void AssertTriggerValidators(this WebServiceException ex)
        {
            var errors = ex.ResponseStatus.Errors;

            Assert.That(errors.First(x => x.FieldName == "CreditCard").ErrorCode, Is.EqualTo("CreditCard"));
            Assert.That(errors.First(x => x.FieldName == "Email").ErrorCode, Is.EqualTo("Email"));
            Assert.That(errors.First(x => x.FieldName == "Email").ErrorCode, Is.EqualTo("Email"));
            Assert.That(errors.First(x => x.FieldName == "Empty").ErrorCode, Is.EqualTo("Empty"));
            Assert.That(errors.First(x => x.FieldName == "Equal").ErrorCode, Is.EqualTo("Equal"));
            Assert.That(errors.First(x => x.FieldName == "ExclusiveBetween").ErrorCode, Is.EqualTo("ExclusiveBetween"));
            Assert.That(errors.First(x => x.FieldName == "GreaterThan").ErrorCode, Is.EqualTo("GreaterThan"));
            Assert.That(errors.First(x => x.FieldName == "GreaterThanOrEqual").ErrorCode, Is.EqualTo("GreaterThanOrEqual"));
            Assert.That(errors.First(x => x.FieldName == "InclusiveBetween").ErrorCode, Is.EqualTo("InclusiveBetween"));
            Assert.That(errors.First(x => x.FieldName == "Length").ErrorCode, Is.EqualTo("Length"));
            Assert.That(errors.First(x => x.FieldName == "LessThan").ErrorCode, Is.EqualTo("LessThan"));
            Assert.That(errors.First(x => x.FieldName == "LessThanOrEqual").ErrorCode, Is.EqualTo("LessThanOrEqual"));
            Assert.That(errors.First(x => x.FieldName == "NotEmpty").ErrorCode, Is.EqualTo("NotEmpty"));
            Assert.That(errors.First(x => x.FieldName == "NotEqual").ErrorCode, Is.EqualTo("NotEqual"));
            Assert.That(errors.First(x => x.FieldName == "Null").ErrorCode, Is.EqualTo("Null"));
            Assert.That(errors.First(x => x.FieldName == "RegularExpression").ErrorCode, Is.EqualTo("RegularExpression"));
            Assert.That(errors.First(x => x.FieldName == "ScalePrecision").ErrorCode, Is.EqualTo("ScalePrecision"));
        }
コード例 #19
0
        private void ThrowIfError <TResponse>(MockHttpResponse httpRes)
        {
            if (httpRes.StatusCode >= 400)
            {
                var webEx = new WebServiceException("WebServiceException, StatusCode: " + httpRes.StatusCode)
                {
                    StatusCode        = httpRes.StatusCode,
                    StatusDescription = httpRes.StatusDescription,
                };

                try
                {
                    var deserializer = HostContext.ContentTypes.GetStreamDeserializer(httpReq.ResponseContentType);
                    webEx.ResponseDto = deserializer(typeof(TResponse), new MemoryStream(httpRes.ReadAsBytes()));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }

                throw webEx;
            }
        }
コード例 #20
0
        private void ThrowIfError <TResponse>(HttpResponseMock httpRes)
        {
            if (httpRes.StatusCode >= 400)
            {
                var webEx = new WebServiceException("WebServiceException, StatusCode: " + httpRes.StatusCode)
                {
                    StatusCode        = httpRes.StatusCode,
                    StatusDescription = httpRes.StatusDescription,
                };

                try
                {
                    var deserializer = EndpointHost.AppHost.ContentTypeFilters.GetStreamDeserializer(httpReq.ResponseContentType);
                    webEx.ResponseDto = deserializer(typeof(TResponse), httpRes.OutputStream);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }

                throw webEx;
            }
        }
コード例 #21
0
            public TResponse Send <TResponse>(object request)
            {
                var message    = MessageFactory.Create(request);
                var response   = ServiceManager.ExecuteMessage(message);
                var httpResult = response as IHttpResult;

                if (httpResult != null)
                {
                    if (httpResult.StatusCode >= HttpStatusCode.BadRequest)
                    {
                        var webEx = new WebServiceException(httpResult.StatusDescription)
                        {
                            ResponseDto = httpResult.Response,
                            StatusCode  = httpResult.Status,
                        };
                        throw webEx;
                    }
                    return((TResponse)httpResult.Response);
                }

                var responseStatus = response.GetResponseStatus();
                var isError        = responseStatus != null && responseStatus.ErrorCode != null;

                if (isError)
                {
                    var webEx = new WebServiceException(responseStatus.Message)
                    {
                        ResponseDto = response,
                        StatusCode  = responseStatus.Errors != null && responseStatus.Errors.Count > 0
                            ? 400
                            : 500,
                    };
                    throw webEx;
                }

                return((TResponse)response);
            }
コード例 #22
0
        internal static ComposerException Create(WebServiceException source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var errors = source.GetFieldErrors().Select(error => new ErrorViewModel
            {
                ErrorCode    = error.ErrorCode,
                ErrorMessage = error.Message
            }).ToList();

            if (errors.All(e => e.ErrorCode != source.ErrorCode))
            {
                errors.Add(new ErrorViewModel
                {
                    ErrorCode    = source.ErrorCode,
                    ErrorMessage = source.ErrorMessage
                });
            }

            return(new ComposerException(errors));
        }
コード例 #23
0
ファイル: Dayton.cs プロジェクト: alefurman40/api_2
 public static WebServiceException[] ParseSoapException(System.Web.Services.Protocols.SoapException soapException)
 {
     WebServiceException[] exceptions;
     try
     {
         exceptions = new WebServiceException[soapException.Detail.ChildNodes.Count];
         for (int i = 0; i < exceptions.Length; i++)
         {
             exceptions[i] = new WebServiceException
                                 (Convert.ToInt32(soapException.Detail.ChildNodes[i].Attributes["e:number"].Value)
                                 , soapException.Detail.ChildNodes[i].Attributes["e:type"].Value
                                 , soapException.Detail.ChildNodes[i].Attributes["e:message"].Value);
         }
         return(exceptions);
     }
     catch (Exception exception)
     {
         throw exception;
     }
     finally
     {
         exceptions = null;
     }
 }
コード例 #24
0
        /// <summary>
        /// Parse the Response For Deployments And Return Them
        /// </summary>
        /// <param name="httpWebResponse">The Response From the Web Service</param>
        /// <returns>List of Deployments</returns>
        private static ServiceDashboardResponse ParseResponseFromJson(HttpWebResponse httpWebResponse)
        {
            //try
            //{
            if (httpWebResponse.StatusCode == HttpStatusCode.OK)
            {
                //if (httpWebResponse.ContentType==)

                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ServiceDashboardResponse));

                if (httpWebResponse.ContentLength > int.MaxValue)
                {
                    throw new IndexOutOfRangeException(String.Format("Response From Web Service Exceeds {0}", int.MaxValue));
                }

                // WWB: Read The Data From The Response Stream
                int length = (int)httpWebResponse.ContentLength;
                byte[] data = new byte[length];
                using (Stream responseStream = httpWebResponse.GetResponseStream())
                {
                    responseStream.Read(data, 0, length);
                }

                // WWB: In A Memory Stream Convert the Json
                using (MemoryStream stream = new MemoryStream(data))
                {
                    var response = serializer.ReadObject(stream) as ServiceDashboardResponse;

                    // WWB: Check The Response For Errors
                    if (response.Status != ServiceDashboardResponseStatus.Success)
                    {
                        var exception = new WebServiceException<ServiceDashboardResponseStatus>()
                        {
                            Status = response.Status
                        };

                        throw exception;
                    }

                    return response;
                }
            }
            else
            {
                ServiceDashboardResponse ErrorResponse = new ServiceDashboardResponse()
                {
                    Status = ServiceDashboardResponseStatus.IllegalResponse,
                    Dashboard = null
                };

                return ErrorResponse;
            }
            //}
            //catch (Exception ex)
            //{
            //    String message = ex.Message;
            //    //if (ex is SerializationException)
            //    //{
            //    //    return ServiceDashboardResponse ErrorResponse = new ServiceDashboardResponse()
            //    //        {
            //    //              Status = ServiceDashboardResponse.IllegalResponse,
                                    //Dashboard = null,
                                    //ServiceCode = String.Empty
            //    //        };
            //    //}
            //    throw new Exception();
            //}
        }
コード例 #25
0
ファイル: AuthTestsBase.cs プロジェクト: KqSMea8/gueslang
 protected void AssertUnAuthorized(WebServiceException webEx)
 {
     Assert.That(webEx.StatusCode, Is.EqualTo((int)HttpStatusCode.Unauthorized));
     Assert.That(webEx.StatusDescription, Is.EqualTo(HttpStatusCode.Unauthorized.ToString()));
 }
コード例 #26
0
 private static bool IsDuplicateAttachmentException(WebServiceException exception)
 {
     return(exception.ErrorCode?.Equals("DuplicateImportedAttachmentException", StringComparison.InvariantCultureIgnoreCase) ?? false);
 }
コード例 #27
0
 private static bool IsDuplicateFailure(WebServiceException exception)
 {
     return((exception.ErrorCode?.Equals("FieldDataFileImportFailureException", StringComparison.InvariantCultureIgnoreCase) ?? false) &&
            exception.ErrorMessage?.IndexOf("Saving parsed data would result in duplicates", StringComparison.InvariantCultureIgnoreCase) >= 0);
 }
コード例 #28
0
ファイル: Client.cs プロジェクト: dfberry/WAZDash
        private static Configuration ParseConfiguration(HttpWebResponse httpWebResponse)
        {
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ConfigurationResponse));

            var response = serializer.ReadObject(httpWebResponse.GetResponseStream()) as ConfigurationResponse;

            // WWB: Check The Response For Errors
            if (response.Status != ConfigurationResponseStatus.Success)
            {
                var exception = new WebServiceException<ConfigurationResponseStatus>()
                {
                    Status = response.Status
                };

                throw exception;
            }

            return response.Configuration;
        }
コード例 #29
0
 public SamplesApiException(string message, WebServiceException originalException)
     : base(message, originalException)
 {
     StatusCode = originalException.StatusCode;
 }
コード例 #30
0
ファイル: AuthTestsBase.cs プロジェクト: AVee/ServiceStack
 protected void AssertUnAuthorized(WebServiceException webEx)
 {
     Assert.That(webEx.StatusCode, Is.EqualTo((int)HttpStatusCode.Unauthorized));
     Assert.That(webEx.StatusDescription, Is.EqualTo(HttpStatusCode.Unauthorized.ToString()));
 }
コード例 #31
0
 private static void Assert404(WebServiceException webEx)
 {
     Assert.That(webEx.StatusCode, Is.EqualTo(404));
     Assert.That(webEx.ResponseStatus.ErrorCode, Is.EqualTo(HttpStatusCode.NotFound.ToString()));
     Assert.That(webEx.ResponseStatus.Message, Is.EqualTo("Custom Status Description"));
 }
コード例 #32
0
 private static bool IsTimeSeriesLocked(WebServiceException exception)
 {
     return(exception.ErrorCode == "DeleteLockedTimeSeriesException");
 }
コード例 #33
0
 public SamplesApiException(string message, WebServiceException originalException, SamplesErrorResponse errorResponse)
     : base(message, originalException)
 {
     StatusCode   = originalException.StatusCode;
     SamplesError = errorResponse;
 }
コード例 #34
0
ファイル: Client.cs プロジェクト: dfberry/WAZDash
        private static AzureFunctionCheckResponse ParseResponseObjectsOpStatusResponse(HttpWebResponse httpWebResponse)
        {
            //try
            //{
            if (httpWebResponse.StatusCode == HttpStatusCode.OK)
            {
                //if (httpWebResponse.ContentType==)

                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(AzureFunctionCheckResponse));

                if (httpWebResponse.ContentLength > int.MaxValue)
                {
                    throw new IndexOutOfRangeException(String.Format("Response From Web Service Exceeds {0}", int.MaxValue));
                }

                // WWB: Read The Data From The Response Stream
                int length = (int)httpWebResponse.ContentLength;
                byte[] data = new byte[length];
                using (Stream responseStream = httpWebResponse.GetResponseStream())
                {
                    responseStream.Read(data, 0, length);
                }

                // WWB: In A Memory Stream Convert the Json
                using (MemoryStream stream = new MemoryStream(data))
                {
                    var response = serializer.ReadObject(stream) as AzureFunctionCheckResponse;

                    // WWB: Check The Response For Errors
                    if (response.WindowsAzureStatus != AzureFunctionCheckResponseStatus.Success)
                    {
                        var exception = new WebServiceException<AzureFunctionCheckResponseStatus>()
                        {
                            Status = response.WindowsAzureStatus
                        };

                        throw exception;
                    }

                    return response;
                }
            }
            else
            {
                AzureFunctionCheckResponse ErrorResponse = new AzureFunctionCheckResponse()
                {
                    WindowsAzureStatus = AzureFunctionCheckResponseStatus.IllegalResponse,
                    FunctionCheckResult = null,
                    RequestId = String.Empty,
                    FunctionName = String.Empty
                };

                return ErrorResponse;
            }
        }
コード例 #35
0
        public static string FormatExceptionForWeb(int currentUserId, string componentName, string pageName, WebServiceException ex)
        {
            StringBuilder msg = new StringBuilder();

            msg.Append(HtmlBuilder.GetLineBreak(3));

            msg.AppendLine(HtmlBuilder.WrapInBoldTags("An unexpected error has occurred.  Please notify your System Administrator.") + HtmlBuilder.GetLineBreak(2));

            msg.Append(HtmlBuilder.WrapInBoldTags("****ENVIRONMENT DETAILS****") + HtmlBuilder.GetLineBreak());
            msg.Append(HtmlBuilder.WrapInBoldTags("Component Name: ") + componentName + HtmlBuilder.GetLineBreak());
            msg.Append(HtmlBuilder.WrapInBoldTags("Page Name: ") + pageName + HtmlBuilder.GetLineBreak());
            msg.Append(HtmlBuilder.WrapInBoldTags("UserId: ") + currentUserId.ToString() + HtmlBuilder.GetLineBreak());
            msg.Append(HtmlBuilder.WrapInBoldTags("Date/time: ") + DateTime.Now.ToString() + HtmlBuilder.GetLineBreak(2));

            do
            {
                msg.Append(HtmlBuilder.WrapInBoldTags("****EXCEPTION DETAILS****") + HtmlBuilder.GetLineBreak());
                msg.Append(HtmlBuilder.WrapInBoldTags("Exception Type: ") + ex.SourceExceptionTypeName + HtmlBuilder.GetLineBreak());
                msg.Append(HtmlBuilder.WrapInBoldTags("Source: ") + ex.Source + HtmlBuilder.GetLineBreak());
                msg.Append(HtmlBuilder.WrapInBoldTags("Message: ") + ex.Message + HtmlBuilder.GetLineBreak());
                msg.Append(HtmlBuilder.WrapInBoldTags("Target Site: ") + ex.TargetSite + HtmlBuilder.GetLineBreak());
                msg.Append(HtmlBuilder.WrapInBoldTags("Stack Trace: ") + ex.StackTrace);

                msg.Append(HtmlBuilder.GetLineBreak(2));

                ex = ex.InnerException;
            }while (ex != null);

            Literal lit = new Literal();

            lit.Text = msg.ToString();

            Panel pnl = new Panel();

            pnl.ForeColor  = ColorTranslator.FromHtml("#4d4f53");
            pnl.Font.Names = new string[] { "Tahoma", "Arial" };
            pnl.Font.Size  = new FontUnit("13px");
            pnl.Controls.Add(lit);

            return(HtmlBuilder.GetServerControlHtml(pnl));
        }
コード例 #36
0
 public SamplesAuthenticationException(string message, WebServiceException originalException)
     : base(message, originalException)
 {
 }
コード例 #37
0
 public SamplesAuthenticationException(string message, WebServiceException originalException, SamplesErrorResponse errorResponse)
     : base(message, originalException, errorResponse)
 {
 }
コード例 #38
0
 private static void Assert404(WebServiceException webEx)
 {
     Assert.That(webEx.StatusCode, Is.EqualTo(404));
     Assert.That(webEx.ResponseStatus.ErrorCode, Is.EqualTo(HttpStatusCode.NotFound.ToString()));
     Assert.That(webEx.ResponseStatus.Message, Is.EqualTo("Custom Status Description"));
 }