Fauna v10 .NET/C# Driver 0.2.0-beta
 
Loading...
Searching...
No Matches
ExceptionFactory.cs
Go to the documentation of this file.
1using System.Net;
2using Fauna.Mapping;
3
5
6public static class ExceptionFactory
7{
8 public static Exception FromQueryFailure(MappingContext ctx, QueryFailure f)
9 {
10 var msg =
11 $"{f.StatusCode} ({f.ErrorCode}): {f.Message}{(f.Summary is { Length: > 0 } ? "\n---\n" + f.Summary : "")}";
12
13 return f.ErrorCode switch
14 {
15 "abort" => new AbortException(msg, f, ctx),
16 "bad_gateway" => new BadGatewayException(msg, f),
17 "contended_transaction" => new ContendedTransactionException(msg, f),
18 "forbidden" => new ForbiddenException(msg, f),
19 "internal_error" => new ServiceException(msg, f),
20 "invalid_argument" => new QueryRuntimeException(msg, f),
21 "invalid_query" => new QueryCheckException(msg, f),
22 "invalid_request" => new InvalidRequestException(msg, f),
23 "limit_exceeded" => new ThrottlingException(msg, f),
24 "time_out" => new QueryTimeoutException(msg, f),
25 "gateway_timeout" => new NetworkException(msg, f.StatusCode, f.Message),
26 "unauthorized" => new UnauthorizedException(msg, f),
27
28 _ => new QueryRuntimeException(msg, f)
29 };
30 }
31
32
33 public static Exception FromRawResponse(string body, HttpResponseMessage r)
34 {
35 if (r.StatusCode is >= HttpStatusCode.OK and <= (HttpStatusCode)299)
36 {
37 // We should never get here, but if we do it's outside of the expected wire protocol.
38 return new ProtocolException("Malformed response.", r.StatusCode, body);
39 }
40
41 return r.StatusCode switch
42 {
43 HttpStatusCode.TooManyRequests => new ThrottlingException(
44 $"{r.StatusCode}: {r.ReasonPhrase ?? "Too many requests."}"),
45 _ => new FaunaException($"{r.StatusCode}: {r.ReasonPhrase}")
46 };
47 }
48}
Represents an exception that occurs when the FQL abort function is called. This exception captures th...
Represents an exception thrown for a bad gateway. Corresponds to the 'bad_gateway' error code in Faun...
Represents an exception that occurs when a transaction is aborted due to concurrent modification....
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...
Represents exceptions caused by invalid requests to Fauna.
Represents exceptions when a response does not match the wire protocol.
Represents exceptions thrown when the query has syntax errors.
Represents exceptions thrown when the query fails at runtime.
Represents exceptions thrown when the query execution time exceeds the specified or default timeout p...
Represents an exception related to Fauna service errors, particularly for query failures.
Represents an exception that indicates some capacity limit was exceeded and thus the request could no...
Represents an exception thrown when there is an authorization error in Fauna. Corresponds to the 'una...
A class representing the mapping context to be used during serialization and deserialization.
Represents a failed query response.
HttpStatusCode StatusCode