Skip to content

Commit

Permalink
Added new exception type and tests: ConnectionReadTimeoutException
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyHeap-NeoTech committed Nov 11, 2021
1 parent e526b09 commit 81fbc50
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ internal static class ExceptionManager
{ typeof(ResultConsumedException), "ResultConsumedError" },
{ typeof(TransactionNestingException), "TransactionNestingException" },
{ typeof(TokenExpiredException), "TokenExpiredError" },
{ typeof(ConnectionReadTimeoutException), "ConnectionReadTimeoutError"},

{ typeof(NotSupportedException), "NotSupportedException" }
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task ShouldReadAndThrowOnTimeout()

ex.Should().NotBeNull();
ex.Should()
.BeOfType<ServiceUnavailableException>()
.BeOfType<ConnectionReadTimeoutException>()
.Which.Message.Should()
.Be($"Socket/Stream timed out afer {timeout}ms, socket closed.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static async Task<int> ReadWithTimeoutAsync(this Stream stream, byte[] bu
if (cancellationDelayTask.IsCanceled || cancellationDelayTask.IsCompleted)
{
stream.Close();
throw new ServiceUnavailableException($"Socket/Stream timed out afer {timeoutMS}ms, socket closed.");
throw new ConnectionReadTimeoutException($"Socket/Stream timed out afer {timeoutMS}ms, socket closed.");
}

// Means that main task completed. We use Result directly.
Expand Down
34 changes: 29 additions & 5 deletions Neo4j.Driver/Neo4j.Driver/Neo4jException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,35 @@ public SessionExpiredException(string message, Exception innerException) : base(
}
}

/// <summary>
/// There was a bolt protocol violation of the contract between the driver and the server.
/// When seen this error, contact driver developers.
/// </summary>
[DataContract]
/// <summary>
/// A <see cref="ConnectionReadTimeoutException"/> indicates that the driver timed out trying to read from the network socket.
/// </summary>
[DataContract]
public class ConnectionReadTimeoutException : Neo4jException
{
/// <summary>
/// Create a new <see cref="ConnectionReadTimeoutException"/> with an error message.
/// </summary>
/// <param name="message">The error message.</param>
public ConnectionReadTimeoutException(string message) : base(message)
{
}

/// <summary>
/// Create a new <see cref="ConnectionReadTimeoutException"/> with an error message and an exception.
/// </summary>
/// <param name="message">The error message.</param>
/// <param name="innerException">The inner exception.</param>
public ConnectionReadTimeoutException(string message, Exception innerException) : base(message, innerException)
{
}
}

/// <summary>
/// There was a bolt protocol violation of the contract between the driver and the server.
/// When seen this error, contact driver developers.
/// </summary>
[DataContract]
public class ProtocolException : Neo4jException
{
private const string ErrorCodeInvalid = "Neo.ClientError.Request.Invalid";
Expand Down

0 comments on commit 81fbc50

Please sign in to comment.