Fauna v10 .NET/C# Driver 0.2.0-beta
 
Loading...
Searching...
No Matches
ServiceException.cs
Go to the documentation of this file.
1using System.Net;
2using Fauna.Mapping;
4
5namespace Fauna.Exceptions;
6
10public interface IRetryableException { }
11
16{
20 public HttpStatusCode? StatusCode { get; set; }
21
25 public string? ErrorCode { get; init; }
26
30 public string? Summary { get; init; }
31
35 public QueryStats Stats { get; init; }
36
42 public long? TxnTs { get; init; }
43
50 public long? SchemaVersion { get; init; }
51
55 public IDictionary<string, string> QueryTags { get; init; }
56
61 public ServiceException(string message)
62 : base(message)
63 {
64 QueryTags = new Dictionary<string, string>();
65 }
66
72 public ServiceException(string message, QueryFailure failure)
73 : base(message)
74 {
75 StatusCode = failure.StatusCode;
76 ErrorCode = failure.ErrorCode;
77 Summary = failure.Summary;
78 Stats = failure.Stats;
79 TxnTs = failure.LastSeenTxn;
81 QueryTags = failure.QueryTags;
82 }
83}
84
90{
91 private readonly MappingContext _ctx;
92 private readonly Dictionary<Type, object?> _cache = new();
93 private readonly object? _abortRaw;
94
95
102 public AbortException(string message, QueryFailure failure, MappingContext ctx)
103 : base(message, failure)
104 {
105 _ctx = ctx;
106 _abortRaw = failure.Abort;
107 }
108
113 public object? GetData() => GetData(Serializer.Dynamic);
114
120 public T? GetData<T>() where T : notnull => GetData(Serializer.Generate<T>(_ctx));
121
128 public T? GetData<T>(ISerializer<T> serializer)
129 {
130 var typeKey = typeof(T);
131 if (_cache.TryGetValue(typeKey, out var cachedData)) return (T?)cachedData;
132
133 if (_abortRaw == null) return (T?)cachedData;
134
135 var abortDataString = _abortRaw.ToString();
136 if (string.IsNullOrEmpty(abortDataString)) return (T?)cachedData;
137
138 // TODO(matt) pull from context
139 var reader = new Utf8FaunaReader(abortDataString);
140 reader.Read();
141
142 var deserializedResult = serializer.Deserialize(_ctx, ref reader);
143 _cache[typeKey] = deserializedResult;
144 return deserializedResult;
145 }
146}
147
153{
154 public BadGatewayException(string message, QueryFailure failure) : base(message, failure)
155 {
156 }
157}
158
164{
165 public ForbiddenException(string message, QueryFailure failure) : base(message, failure)
166 {
167 }
168}
169
175{
176 public UnauthorizedException(string message, QueryFailure failure) : base(message, failure)
177 {
178 }
179}
180
185{
186 public TimeoutException(string message, QueryFailure failure) : base(message, failure)
187 {
188 }
189}
190
195{
196 public QueryTimeoutException(string message, QueryFailure failure) : base(message, failure)
197 {
198 }
199}
200
205{
206 public QueryCheckException(string message, QueryFailure failure) : base(message, failure)
207 {
208 }
209}
210
215{
216 public QueryRuntimeException(string message, QueryFailure failure) : base(message, failure)
217 {
218 }
219}
220
226{
227 public ThrottlingException(string message) : base(message)
228 {
229 StatusCode = HttpStatusCode.TooManyRequests;
230 }
231 public ThrottlingException(string message, QueryFailure failure) : base(message, failure)
232 {
233 }
234}
235
240{
241 public InvalidRequestException(string message, QueryFailure failure) : base(message, failure)
242 {
243 }
244}
245
251{
252 public ContendedTransactionException(string message, QueryFailure failure) : base(message, failure)
253 {
254 }
255}
256
257// <summary>
258// Represents an exception that occurs when a request fails due to a network issue.
259// </summary>
261{
262 public string ResponseBody { get; init; }
263
264 public HttpStatusCode StatusCode { get; init; }
265
266 public NetworkException(string message, HttpStatusCode statusCode, string body)
267 : base(message)
268 {
269 StatusCode = statusCode;
270 ResponseBody = body;
271 }
272}
Represents an exception that occurs when the FQL abort function is called. This exception captures th...
T? GetData< T >()
Retrieves the deserialized data associated with the abort operation as a specific type.
object? GetData()
Retrieves the deserialized data associated with the abort operation as an object.
AbortException(string message, QueryFailure failure, MappingContext ctx)
Initializes a new instance of the AbortException class with a specified error message and query failu...
Represents an exception thrown for a bad gateway. Corresponds to the 'bad_gateway' error code in Faun...
BadGatewayException(string message, QueryFailure failure)
Represents an exception that occurs when a transaction is aborted due to concurrent modification....
ContendedTransactionException(string message, QueryFailure failure)
Represents the base exception class for all exceptions specific to Fauna interactions.
Represents an exception thrown when access to a resource is not allowed. Corresponds to the 'forbidde...
ForbiddenException(string message, QueryFailure failure)
Represents exceptions caused by invalid requests to Fauna.
InvalidRequestException(string message, QueryFailure failure)
NetworkException(string message, HttpStatusCode statusCode, string body)
Represents exceptions thrown when the query has syntax errors.
QueryCheckException(string message, QueryFailure failure)
Represents exceptions thrown when the query fails at runtime.
QueryRuntimeException(string message, QueryFailure failure)
Represents exceptions thrown when the query execution time exceeds the specified or default timeout p...
QueryTimeoutException(string message, QueryFailure failure)
Represents an exception related to Fauna service errors, particularly for query failures.
IDictionary< string, string > QueryTags
The tags on the x-query-tags header, if it was provided.
string? Summary
A comprehensive, human readable summary of any errors, warnings and/or logs returned from the query.
long? SchemaVersion
The schema version used by the query. This can be used by clients displaying schema to determine when...
HttpStatusCode? StatusCode
The HTTP status code.
string? ErrorCode
The error code when a query fails.
ServiceException(string message)
Initializes a new instance of the ServiceException class with a specified query failure details and e...
long? TxnTs
The transaction commit time in micros since epoch. Used by drivers to populate the x-last-txn-ts requ...
ServiceException(string message, QueryFailure failure)
Initializes a new instance of the ServiceException class with a specified query failure details and e...
Represents an exception that indicates some capacity limit was exceeded and thus the request could no...
ThrottlingException(string message, QueryFailure failure)
Represents exceptions thrown when the query execution time exceeds the specified or default timeout p...
TimeoutException(string message, QueryFailure failure)
Represents an exception thrown when there is an authorization error in Fauna. Corresponds to the 'una...
UnauthorizedException(string message, QueryFailure failure)
A class representing the mapping context to be used during serialization and deserialization.
Represents a failed query response.
HttpStatusCode StatusCode
QueryStats Stats
Gets the statistics related to the query execution.
Dictionary< string, string > QueryTags
Gets a dictionary of query tags, providing additional context about the query.
string Summary
Gets a summary of the query execution.
long LastSeenTxn
Gets the last transaction seen by this query.
long SchemaVersion
Gets the schema version.
Represents an interface for exceptions that are potentially recoverable through retrying the failed o...
Contains statistics related to the execution of a query in the Fauna database.
Definition QueryStats.cs:10
Represents a reader that provides fast, non-cached, forward-only access to serialized data.