public void ServiceUnavailableExceptionConstructorTest1()
        {
            ServiceUnavailableException target = new ServiceUnavailableException();

            Assert.IsNotNull(target);
            Assert.IsNotNull(target.Message);
        }
            public async Task ShouldLogServiceUnavailable()
            {
                var error        = new ServiceUnavailableException("Procedure not found");
                var uri          = new Uri("neo4j://123:456");
                var routingTable = new RoutingTable(null, new List <Uri> {
                    uri
                });
                var poolManagerMock = new Mock <IClusterConnectionPoolManager>();

                poolManagerMock.Setup(x => x.CreateClusterConnectionAsync(uri))
                .Returns(Task.FromResult(new Mock <IConnection>().Object));

                var discovery = new Mock <IDiscovery>();

                discovery.Setup(x => x.DiscoverAsync(It.IsAny <IConnection>(), "", null, Bookmark.Empty)).Throws(error);

                var logger = new Mock <ILogger>();

                logger.Setup(x => x.Warn(It.IsAny <Exception>(), It.IsAny <string>(), It.IsAny <object[]>()));

                var manager = NewRoutingTableManager(routingTable, poolManagerMock.Object, discovery.Object,
                                                     logger: logger.Object);

                await manager.UpdateRoutingTableAsync(routingTable, AccessMode.Read, "", null, Bookmark.Empty);

                logger.Verify(x => x.Warn(error, It.IsAny <string>(), It.IsAny <object[]>()));
            }
Пример #3
0
 public static ErrorResponse ToErrorResponse(this ServiceUnavailableException e)
 {
     return(new ErrorResponse()
     {
         Code = e.Code,
         Message = e.Message
     });
 }
        public void ServiceUnavailableExceptionConstructorTest()
        {
            string msg = "TestValue"; // TODO: Initialize to an appropriate value
            ServiceUnavailableException target = new ServiceUnavailableException(msg);

            Assert.IsNotNull(target);
            Assert.AreEqual(msg, target.Message);
        }
Пример #5
0
        public void ContructorTest()
        {
            Assert.True(typeof(ServiceUnavailableException).IsSubclassOf(typeof(MtgExceptionBase)));

            ServiceUnavailableException exception = new ServiceUnavailableException("testing");

            Assert.Equal("MTG Api Error, testing", exception.Message);
        }
 /// <summary>Initializes a new instance of the <see cref="InvalidModelStateResult"/> class.</summary>
 /// <param name="exception">The ServiceUnavailable exception information to include in the error.</param>
 /// <param name="includeErrorDetail">
 /// <see langword="true"/> if the error should include exception messages; otherwise, <see langword="false"/>.
 /// </param>
 /// <param name="contentNegotiator">The content negotiator to handle content negotiation.</param>
 /// <param name="request">The request message which led to this result.</param>
 /// <param name="formatters">The formatters to use to negotiate and format the content.</param>
 public ServiceUnavailableExceptionResult(
     ServiceUnavailableException exception,
     bool includeErrorDetail,
     IContentNegotiator contentNegotiator,
     HttpRequestMessage request,
     IEnumerable <MediaTypeFormatter> formatters)
     : this(exception, new DirectDependencyProvider(includeErrorDetail, contentNegotiator, request, formatters))
 {
 }
Пример #7
0
        public void SerializableTest()
        {
            var request = new HttpRequest(new Uri("http://localhost"), new Dictionary <string, string> {
                { "hello", "tyria" }
            });
            var response = new HttpResponse <ErrorObject>(new ErrorObject {
                Text = "Error"
            }, HttpStatusCode.ServiceUnavailable, null, null);
            var exception = new ServiceUnavailableException(request, response);

            exception.Should().BeBinarySerializable();
        }
Пример #8
0
            public void ConvertConnectionErrorToSessionExpired()
            {
                var connMock    = new Mock <IConnection>();
                var handlerMock = new Mock <IClusterErrorHandler>();
                var clusterConn = new ClusterConnection(connMock.Object, Uri, AccessMode.Read, handlerMock.Object);

                var inError  = new ServiceUnavailableException("Connection error");
                var outError = Record.Exception(() => clusterConn.OnError(inError));

                outError.Should().BeOfType <SessionExpiredException>();
                handlerMock.Verify(x => x.OnConnectionError(Uri, inError), Times.Once);
                handlerMock.Verify(x => x.OnWriteError(Uri), Times.Never);
            }
            public async Task ConvertConnectionErrorToSessionExpired()
            {
                var handlerMock = new Mock <IClusterErrorHandler>();
                var clusterConn =
                    new ClusterConnection(CreateConnectionWithMode(AccessMode.Read), Uri, handlerMock.Object);

                var inError  = new ServiceUnavailableException("Connection error");
                var outError = await Record.ExceptionAsync(() => clusterConn.OnErrorAsync(inError));

                outError.Should().BeOfType <SessionExpiredException>();
                handlerMock.Verify(x => x.OnConnectionErrorAsync(Uri, inError), Times.Once);
                handlerMock.Verify(x => x.OnWriteError(Uri), Times.Never);
            }
        private ServiceUnavailableExceptionResult(
            ServiceUnavailableException exception, IDependencyProvider dependencies)
        {
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }

            Contract.Assert(dependencies != null);

            _exception    = exception;
            _dependencies = dependencies;
        }
        public override AmazonServiceException UnmarshallException(JsonUnmarshallerContext context, Exception innerException, HttpStatusCode statusCode)
        {
            ErrorResponse errorResponse = JsonErrorResponseUnmarshaller.GetInstance().Unmarshall(context);

            if (errorResponse.Code != null && errorResponse.Code.Equals("ResourceNotFoundException"))
            {
                ResourceNotFoundException ex = new ResourceNotFoundException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);

                ex.Type = errorResponse.Metadata["Type"];

                ex.Code = errorResponse.Metadata["Code"];

                return(ex);
            }

            if (errorResponse.Code != null && errorResponse.Code.Equals("MissingParameterValueException"))
            {
                MissingParameterValueException ex = new MissingParameterValueException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);

                ex.Type = errorResponse.Metadata["Type"];

                ex.Code = errorResponse.Metadata["Code"];

                return(ex);
            }

            if (errorResponse.Code != null && errorResponse.Code.Equals("ServiceUnavailableException"))
            {
                ServiceUnavailableException ex = new ServiceUnavailableException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);

                ex.Type = errorResponse.Metadata["Type"];

                ex.Code = errorResponse.Metadata["Code"];

                return(ex);
            }

            if (errorResponse.Code != null && errorResponse.Code.Equals("InvalidParameterValueException"))
            {
                InvalidParameterValueException ex = new InvalidParameterValueException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);

                ex.Type = errorResponse.Metadata["Type"];

                ex.Code = errorResponse.Metadata["Code"];

                return(ex);
            }

            return(new AmazonGlacierException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode));
        }
 /// <summary>Initializes a new instance of the <see cref="InvalidModelStateResult"/> class.</summary>
 /// <param name="exception">The ServiceUnavailable exception information to include in the error.</param>
 /// <param name="controller">The controller from which to obtain the dependencies needed for execution.</param>
 public ServiceUnavailableExceptionResult(ServiceUnavailableException exception, ApiController controller)
     : this(exception, new ApiControllerDependencyProvider(controller))
 {
 }
        /// <summary>
        /// To the exception.
        /// </summary>
        /// <param name="exceptionInfo">The exception information.</param>
        /// <returns>System.Exception.</returns>
        public static Exception ToException(this ExceptionInfo exceptionInfo)
        {
            Exception result = null;

            if (exceptionInfo != null)
            {
                var innerException = exceptionInfo.InnerException;

                switch (exceptionInfo.ExceptionType)
                {
                case "Beyova.Diagnostic.HttpOperationException":
                    return(new HttpOperationException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint));

                case "Beyova.Diagnostic.SqlStoredProcedureException":
                    return(new SqlStoredProcedureException(exceptionInfo.Message, exceptionInfo.Code));

                default:
                    break;
                }

                switch (exceptionInfo.Code.Major)
                {
                case ExceptionCode.MajorCode.CreditNotAfford:
                    result = new CreditNotAffordException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                case ExceptionCode.MajorCode.DataConflict:
                    result = new DataConflictException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                case ExceptionCode.MajorCode.NotImplemented:
                    result = new UnimplementedException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                case ExceptionCode.MajorCode.NullOrInvalidValue:
                    result = new InvalidObjectException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                case ExceptionCode.MajorCode.OperationFailure:
                    result = new OperationFailureException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                case ExceptionCode.MajorCode.OperationForbidden:
                    result = new OperationForbiddenException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                case ExceptionCode.MajorCode.ResourceNotFound:
                    result = new ResourceNotFoundException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                case ExceptionCode.MajorCode.ServiceUnavailable:
                    result = new ServiceUnavailableException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                case ExceptionCode.MajorCode.UnauthorizedOperation:
                    result = new UnauthorizedOperationException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                case ExceptionCode.MajorCode.HttpBlockError:
                    result = new HttpOperationException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                case ExceptionCode.MajorCode.Unsupported:
                    result = new UnsupportedException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                default:
                    result = new Exception(exceptionInfo.Message);
                    break;
                }
            }

            return(result);
        }
Пример #14
0
 private void Handle(WebServiceType type, ServiceUnavailableException ex, string additionalErrorInfo)
 {
     _servicesStatus.SetStatus(type, false, ex.Message);
     _errorHandler.Warn(new Exception(additionalErrorInfo, ex.InnerException));
 }