Skip to content

Commit

Permalink
remove marker interface and add property to neo4j exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
thelonelyvulpes committed May 11, 2022
1 parent 70160d0 commit fe764a8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static Neo4jException ParseServerException(string code, string message)

public static bool IsRetriableError(this Exception error)
{
return error is IRetriableNeo4jException;
return error is Neo4jException neo4JException && neo4JException.CanBeRetried;
}

public static bool IsRecoverableError(this Exception error)
Expand Down
28 changes: 16 additions & 12 deletions Neo4j.Driver/Neo4j.Driver/Neo4jException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,13 @@

namespace Neo4j.Driver
{
/// <summary>
/// Marker interface for Neo4j exceptions that can be retried.
/// </summary>
public interface IRetriableNeo4jException
{
}

/// <summary>
/// The base class for all Neo4j exceptions.
/// </summary>
[DataContract]
public class Neo4jException : Exception
{
internal virtual bool CanBeRetried => false;
/// <summary>
/// Create a new <see cref="Neo4jException"/>
/// </summary>
Expand Down Expand Up @@ -146,8 +140,10 @@ public ClientException(string code, string message, Exception innerException)
/// The error code provided can be used to determine further details for the problem.
/// </summary>
[DataContract]
public class TransientException : Neo4jException, IRetriableNeo4jException
public class TransientException : Neo4jException
{
internal override bool CanBeRetried => true;

/// <summary>
/// Create a new <see cref="TransientException"/>.
/// </summary>
Expand Down Expand Up @@ -223,8 +219,10 @@ public DatabaseException(string code, string message, Exception innerException)
/// A <see cref="ServiceUnavailableException"/> indicates that the driver cannot communicate with the cluster.
/// </summary>
[DataContract]
public class ServiceUnavailableException : Neo4jException, IRetriableNeo4jException
public class ServiceUnavailableException : Neo4jException
{
internal override bool CanBeRetried => true;

/// <summary>
/// Create a new <see cref="ServiceUnavailableException"/> with an error message.
/// </summary>
Expand All @@ -250,8 +248,10 @@ public ServiceUnavailableException(string message, Exception innerException) : b
/// A new session needs to be acquired from the driver and all actions taken on the expired session must be replayed.
/// </summary>
[DataContract]
public class SessionExpiredException : Neo4jException, IRetriableNeo4jException
public class SessionExpiredException : Neo4jException
{
internal override bool CanBeRetried => true;

/// <summary>
/// Create a new <see cref="SessionExpiredException"/> with an error message.
/// </summary>
Expand All @@ -274,8 +274,10 @@ public SessionExpiredException(string message, Exception innerException) : base(
/// A <see cref="ConnectionReadTimeoutException"/> indicates that the driver timed out trying to read from the network socket.
/// </summary>
[DataContract]
public class ConnectionReadTimeoutException : Neo4jException, IRetriableNeo4jException
public class ConnectionReadTimeoutException : Neo4jException
{
internal override bool CanBeRetried => true;

/// <summary>
/// Create a new <see cref="ConnectionReadTimeoutException"/> with an error message.
/// </summary>
Expand Down Expand Up @@ -397,8 +399,10 @@ public AuthenticationException(string message) : base(ErrorCode, message)
/// <summary>
/// The authorization information maintained on the server has expired. The client should reconnect.
/// </summary>
public class AuthorizationException : SecurityException, IRetriableNeo4jException
public class AuthorizationException : SecurityException
{
internal override bool CanBeRetried => true;

private const string ErrorCode = "Neo.ClientError.Security.AuthorizationExpired";

internal static bool IsAuthorizationError(string code)
Expand Down

0 comments on commit fe764a8

Please sign in to comment.