Fauna .NET Driver 0.1.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(Deserializer.Dynamic);
114
121 public T? GetData<T>() where T : notnull => GetData(Deserializer.Generate<T>(_ctx));
122
129 public T? GetData<T>(IDeserializer<T> deserializer)
130 {
131 var typeKey = typeof(T);
132 if (_cache.TryGetValue(typeKey, out var cachedData)) return (T?)cachedData;
133
134 if (_abortRaw == null) return (T?)cachedData;
135
136 var abortDataString = _abortRaw.ToString();
137 if (string.IsNullOrEmpty(abortDataString)) return (T?)cachedData;
138
139 // TODO(matt) pull from context
140 var reader = new Utf8FaunaReader(abortDataString);
141 reader.Read();
142
143 var deserializedResult = deserializer.Deserialize(_ctx, ref reader);
144 _cache[typeKey] = deserializedResult;
145 return deserializedResult;
146 }
147}
148
154{
155 public BadGatewayException(string message, QueryFailure failure) : base(message, failure)
156 {
157 }
158}
159
165{
166 public ForbiddenException(string message, QueryFailure failure) : base(message, failure)
167 {
168 }
169}
170
176{
177 public UnauthorizedException(string message, QueryFailure failure) : base(message, failure)
178 {
179 }
180}
181
186{
187 public TimeoutException(string message, QueryFailure failure) : base(message, failure)
188 {
189 }
190}
191
196{
197 public QueryTimeoutException(string message, QueryFailure failure) : base(message, failure)
198 {
199 }
200}
201
206{
207 public QueryCheckException(string message, QueryFailure failure) : base(message, failure)
208 {
209 }
210}
211
216{
217 public QueryRuntimeException(string message, QueryFailure failure) : base(message, failure)
218 {
219 }
220}
221
227{
228 public ThrottlingException(string message) : base(message)
229 {
230 StatusCode = HttpStatusCode.TooManyRequests;
231 }
232 public ThrottlingException(string message, QueryFailure failure) : base(message, failure)
233 {
234 }
235}
236
241{
242 public InvalidRequestException(string message, QueryFailure failure) : base(message, failure)
243 {
244 }
245}
246
252{
253 public ContendedTransactionException(string message, QueryFailure failure) : base(message, failure)
254 {
255 }
256}
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)
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...
QueryStats Stats
The query stats for the request.
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)
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.