Skip to content

Commit

Permalink
Refactored FaunaClientException and FaunaServiceException derived exc…
Browse files Browse the repository at this point in the history
…eptions
  • Loading branch information
aotroshko committed Dec 19, 2023
1 parent c58bbf8 commit 5a3bad3
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 40 deletions.
6 changes: 3 additions & 3 deletions Fauna/Client/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ public async Task<QuerySuccess<T>> QueryAsync<T>(

// Server/Network Errors
"internal_error" => new FaunaServiceException(FormatMessage("Internal Error"), failure),
"bad_gateway" => new FaunaNetworkException(FormatMessage("Bad Gateway"), failure),
"timeout" => new FaunaQueryTimeoutException(FormatMessage("Timeout"), failure),
"gateway_timeout" => new FaunaNetworkException(FormatMessage("Gateway Timeout"), failure),
"bad_gateway" => new FaunaNetworkException(FormatMessage("Bad Gateway")),
"gateway_timeout" => new FaunaNetworkException(FormatMessage("Gateway Timeout")),

_ => new FaunaBaseException(FormatMessage("Unexpected Error"), failure),
_ => new FaunaBaseException(FormatMessage("Unexpected Error")),
};
}
else
Expand Down
8 changes: 4 additions & 4 deletions Fauna/Client/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task<QueryResponse> DoPostAsync<T>(
}
catch (TimeoutException ex)
{
throw new FaunaQueryTimeoutException(FormatMessage("Operation Timed Out", ex.Message), ex);
throw new FaunaClientException(FormatMessage("Operation Timed Out", ex.Message), ex);
}
catch (TaskCanceledException ex)
{
Expand All @@ -64,7 +64,7 @@ public async Task<QueryResponse> DoPostAsync<T>(
}
else
{
throw new FaunaQueryTimeoutException(FormatMessage("Operation Timed Out", ex.Message), ex);
throw new FaunaClientException(FormatMessage("Operation Timed Out", ex.Message), ex);
}
}
catch (ArgumentNullException ex)
Expand All @@ -81,11 +81,11 @@ public async Task<QueryResponse> DoPostAsync<T>(
}
catch (AuthenticationException ex)
{
throw new FaunaServiceException(FormatMessage("Authentication Failed", ex.Message), ex);
throw new FaunaClientException(FormatMessage("Authentication Failed", ex.Message), ex);
}
catch (NotSupportedException ex)
{
throw new FaunaInvalidRequestException(FormatMessage("Not Supported Operation", ex.Message), ex);
throw new FaunaClientException(FormatMessage("Not Supported Operation", ex.Message), ex);
}
catch (Exception ex)
{
Expand Down
19 changes: 2 additions & 17 deletions Fauna/Exceptions/FaunaBaseException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,10 @@
/// </summary>
public class FaunaBaseException : Exception
{
/// <summary>
/// Gets the QueryFailure object associated with the exception, if any.
/// It provides information about the failure in the context of a Fauna query.
/// </summary>
public QueryFailure? QueryFailure { get; }

public FaunaBaseException() { }

public FaunaBaseException(string message) : base(message) { }

public FaunaBaseException(string message, QueryFailure? queryFailure = null)
: base(message)
{
QueryFailure = queryFailure;
}

public FaunaBaseException(string message, Exception innerException, QueryFailure? queryFailure = null)
: base(message, innerException)
{
QueryFailure = queryFailure;
}
public FaunaBaseException(string message, Exception innerException)
: base(message, innerException) { }
}
8 changes: 4 additions & 4 deletions Fauna/Exceptions/FaunaClientException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
/// </summary>
public class FaunaClientException : FaunaBaseException
{
public FaunaClientException(string message, QueryFailure? queryFailure = null)
: base(message, queryFailure) { }
public FaunaClientException(string message)
: base(message) { }

public FaunaClientException(string message, Exception innerException, QueryFailure? queryFailure = null)
: base(message, innerException, queryFailure) { }
public FaunaClientException(string message, Exception innerException)
: base(message, innerException) { }
}
8 changes: 4 additions & 4 deletions Fauna/Exceptions/FaunaNetworkException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
/// </summary>
public class FaunaNetworkException : FaunaBaseException, IFaunaRetryableException
{
public FaunaNetworkException(string message, QueryFailure? queryFailure = null)
: base(message, queryFailure) { }
public FaunaNetworkException(string message)
: base(message) { }

public FaunaNetworkException(string message, Exception innerException, QueryFailure? queryFailure = null)
: base(message, innerException, queryFailure) { }
public FaunaNetworkException(string message, Exception innerException)
: base(message, innerException) { }
}
8 changes: 4 additions & 4 deletions Fauna/Exceptions/FaunaProtocolException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
/// </summary>
public class FaunaProtocolException : FaunaBaseException
{
public FaunaProtocolException(string message, QueryFailure? queryFailure = null)
: base(message, queryFailure) { }
public FaunaProtocolException(string message)
: base(message) { }

public FaunaProtocolException(string message, Exception innerException, QueryFailure? queryFailure = null)
: base(message, innerException, queryFailure) { }
public FaunaProtocolException(string message, Exception innerException)
: base(message, innerException) { }
}
20 changes: 16 additions & 4 deletions Fauna/Exceptions/FaunaServiceException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@

public class FaunaServiceException : FaunaBaseException
{
public FaunaServiceException(string message, QueryFailure? queryFailure = null)
: base(message, queryFailure) { }
/// <summary>
/// Gets the QueryFailure object associated with the exception.
/// It provides information about the failure in the context of a Fauna query.
/// </summary>
public QueryFailure? QueryFailure { get; }

public FaunaServiceException(string message, Exception innerException, QueryFailure? queryFailure = null)
: base(message, innerException, queryFailure) { }
public FaunaServiceException(string message, QueryFailure queryFailure)
: base(message)
{
QueryFailure = queryFailure;
}

public FaunaServiceException(string message, Exception innerException, QueryFailure queryFailure)
: base(message, innerException)
{
QueryFailure = queryFailure;
}
}

0 comments on commit 5a3bad3

Please sign in to comment.