fauna.errors.errors

  1from typing import Optional, List, Any, Mapping
  2
  3from fauna.encoding import ConstraintFailure, QueryStats, QueryInfo, QueryTags
  4
  5
  6class FaunaException(Exception):
  7  """Base class Fauna Exceptions"""
  8  pass
  9
 10
 11class RetryableFaunaException(FaunaException):
 12  pass
 13
 14
 15class ClientError(FaunaException):
 16  """An error representing a failure internal to the client, itself.
 17    This indicates Fauna was never called - the client failed internally
 18    prior to sending the request."""
 19  pass
 20
 21
 22class NetworkError(FaunaException):
 23  """An error representing a failure due to the network.
 24    This indicates Fauna was never reached."""
 25  pass
 26
 27
 28class ProtocolError(FaunaException):
 29  """An error representing a HTTP failure - but one not directly emitted by Fauna."""
 30
 31  @property
 32  def status_code(self) -> int:
 33    return self._status_code
 34
 35  @property
 36  def message(self) -> str:
 37    return self._message
 38
 39  def __init__(self, status_code: int, message: str):
 40    self._status_code = status_code
 41    self._message = message
 42
 43  def __str__(self):
 44    return f"{self.status_code}: {self.message}"
 45
 46
 47class FaunaError(FaunaException):
 48  """Base class Fauna Errors"""
 49
 50  @property
 51  def status_code(self) -> int:
 52    return self._status_code
 53
 54  @property
 55  def code(self) -> str:
 56    return self._code
 57
 58  @property
 59  def message(self) -> str:
 60    return self._message
 61
 62  @property
 63  def abort(self) -> Optional[Any]:
 64    return self._abort
 65
 66  @property
 67  def constraint_failures(self) -> Optional[List['ConstraintFailure']]:
 68    return self._constraint_failures
 69
 70  def __init__(
 71      self,
 72      status_code: int,
 73      code: str,
 74      message: str,
 75      abort: Optional[Any] = None,
 76      constraint_failures: Optional[List['ConstraintFailure']] = None,
 77  ):
 78    self._status_code = status_code
 79    self._code = code
 80    self._message = message
 81    self._abort = abort
 82    self._constraint_failures = constraint_failures
 83
 84  def __str__(self):
 85    return f"{self.status_code}: {self.code}\n{self.message}"
 86
 87  @staticmethod
 88  def parse_error_and_throw(body: Any, status_code: int):
 89    err = body["error"]
 90    code = err["code"]
 91    message = err["message"]
 92
 93    query_tags = QueryTags.decode(
 94        body["query_tags"]) if "query_tags" in body else None
 95    stats = QueryStats(body["stats"]) if "stats" in body else None
 96    txn_ts = body["txn_ts"] if "txn_ts" in body else None
 97    schema_version = body["schema_version"] if "schema_version" in body else None
 98    summary = body["summary"] if "summary" in body else None
 99
100    constraint_failures: Optional[List[ConstraintFailure]] = None
101    if "constraint_failures" in err:
102      constraint_failures = [
103          ConstraintFailure(
104              message=cf["message"],
105              name=cf["name"] if "name" in cf else None,
106              paths=cf["paths"] if "paths" in cf else None,
107          ) for cf in err["constraint_failures"]
108      ]
109
110    if status_code >= 400 and status_code < 500:
111      if code == "invalid_query":
112        raise QueryCheckError(
113            status_code=400,
114            code=code,
115            message=message,
116            summary=summary,
117            constraint_failures=constraint_failures,
118            query_tags=query_tags,
119            stats=stats,
120            txn_ts=txn_ts,
121            schema_version=schema_version,
122        )
123      elif code == "invalid_request":
124        raise InvalidRequestError(
125            status_code=400,
126            code=code,
127            message=message,
128            summary=summary,
129            constraint_failures=constraint_failures,
130            query_tags=query_tags,
131            stats=stats,
132            txn_ts=txn_ts,
133            schema_version=schema_version,
134        )
135      elif code == "abort":
136        abort = err["abort"] if "abort" in err else None
137        raise AbortError(
138            status_code=400,
139            code=code,
140            message=message,
141            summary=summary,
142            abort=abort,
143            constraint_failures=constraint_failures,
144            query_tags=query_tags,
145            stats=stats,
146            txn_ts=txn_ts,
147            schema_version=schema_version,
148        )
149      elif code == "unauthorized":
150        raise AuthenticationError(
151            status_code=401,
152            code=code,
153            message=message,
154            summary=summary,
155            constraint_failures=constraint_failures,
156            query_tags=query_tags,
157            stats=stats,
158            txn_ts=txn_ts,
159            schema_version=schema_version,
160        )
161      elif code == "forbidden" and status_code == 403:
162        raise AuthorizationError(
163            status_code=403,
164            code=code,
165            message=message,
166            summary=summary,
167            constraint_failures=constraint_failures,
168            query_tags=query_tags,
169            stats=stats,
170            txn_ts=txn_ts,
171            schema_version=schema_version,
172        )
173      elif code == "method_not_allowed":
174        raise QueryRuntimeError(
175            status_code=405,
176            code=code,
177            message=message,
178            summary=summary,
179            constraint_failures=constraint_failures,
180            query_tags=query_tags,
181            stats=stats,
182            txn_ts=txn_ts,
183            schema_version=schema_version,
184        )
185      elif code == "conflict":
186        raise ContendedTransactionError(
187            status_code=409,
188            code=code,
189            message=message,
190            summary=summary,
191            constraint_failures=constraint_failures,
192            query_tags=query_tags,
193            stats=stats,
194            txn_ts=txn_ts,
195            schema_version=schema_version,
196        )
197      elif code == "request_size_exceeded":
198        raise QueryRuntimeError(
199            status_code=413,
200            code=code,
201            message=message,
202            summary=summary,
203            constraint_failures=constraint_failures,
204            query_tags=query_tags,
205            stats=stats,
206            txn_ts=txn_ts,
207            schema_version=schema_version,
208        )
209      elif code == "limit_exceeded":
210        raise ThrottlingError(
211            status_code=429,
212            code=code,
213            message=message,
214            summary=summary,
215            constraint_failures=constraint_failures,
216            query_tags=query_tags,
217            stats=stats,
218            txn_ts=txn_ts,
219            schema_version=schema_version,
220        )
221      elif code == "time_out":
222        raise QueryTimeoutError(
223            status_code=440,
224            code=code,
225            message=message,
226            summary=summary,
227            constraint_failures=constraint_failures,
228            query_tags=query_tags,
229            stats=stats,
230            txn_ts=txn_ts,
231            schema_version=schema_version,
232        )
233      else:
234        raise QueryRuntimeError(
235            status_code=status_code,
236            code=code,
237            message=message,
238            summary=summary,
239            constraint_failures=constraint_failures,
240            query_tags=query_tags,
241            stats=stats,
242            txn_ts=txn_ts,
243            schema_version=schema_version,
244        )
245    elif status_code == 500:
246      raise ServiceInternalError(
247          status_code=status_code,
248          code=code,
249          message=message,
250          summary=summary,
251          constraint_failures=constraint_failures,
252          query_tags=query_tags,
253          stats=stats,
254          txn_ts=txn_ts,
255          schema_version=schema_version,
256      )
257    elif status_code == 503:
258      raise ServiceTimeoutError(
259          status_code=status_code,
260          code=code,
261          message=message,
262          summary=summary,
263          constraint_failures=constraint_failures,
264          query_tags=query_tags,
265          stats=stats,
266          txn_ts=txn_ts,
267          schema_version=schema_version,
268      )
269    else:
270      raise ServiceError(
271          status_code=status_code,
272          code=code,
273          message=message,
274          summary=summary,
275          constraint_failures=constraint_failures,
276          query_tags=query_tags,
277          stats=stats,
278          txn_ts=txn_ts,
279          schema_version=schema_version,
280      )
281
282
283class ServiceError(FaunaError, QueryInfo):
284  """An error representing a query failure returned by Fauna."""
285
286  def __init__(
287      self,
288      status_code: int,
289      code: str,
290      message: str,
291      summary: Optional[str] = None,
292      abort: Optional[Any] = None,
293      constraint_failures: Optional[List['ConstraintFailure']] = None,
294      query_tags: Optional[Mapping[str, str]] = None,
295      stats: Optional[QueryStats] = None,
296      txn_ts: Optional[int] = None,
297      schema_version: Optional[int] = None,
298  ):
299    QueryInfo.__init__(
300        self,
301        query_tags=query_tags,
302        stats=stats,
303        summary=summary,
304        txn_ts=txn_ts,
305        schema_version=schema_version,
306    )
307
308    FaunaError.__init__(
309        self,
310        status_code=status_code,
311        code=code,
312        message=message,
313        abort=abort,
314        constraint_failures=constraint_failures,
315    )
316
317  def __str__(self):
318    constraint_str = "---"
319    if self._constraint_failures:
320      constraint_str = f"---\nconstraint failures: {self._constraint_failures}\n---"
321
322    return f"{self._status_code}: {self.code}\n{self.message}\n{constraint_str}\n{self.summary or ''}"
323
324
325class AbortError(ServiceError):
326  pass
327
328
329class InvalidRequestError(ServiceError):
330  pass
331
332
333class QueryCheckError(ServiceError):
334  """An error due to a "compile-time" check of the query failing."""
335  pass
336
337
338class ContendedTransactionError(ServiceError):
339  """Transaction is aborted due to concurrent modification."""
340  pass
341
342
343class QueryRuntimeError(ServiceError):
344  """An error response that is the result of the query failing during execution.
345    QueryRuntimeError's occur when a bug in your query causes an invalid execution
346    to be requested.
347    The 'code' field will vary based on the specific error cause."""
348  pass
349
350
351class AuthenticationError(ServiceError):
352  """AuthenticationError indicates invalid credentials were used."""
353  pass
354
355
356class AuthorizationError(ServiceError):
357  """AuthorizationError indicates the credentials used do not have
358    permission to perform the requested action."""
359  pass
360
361
362class ThrottlingError(ServiceError, RetryableFaunaException):
363  """ThrottlingError indicates some capacity limit was exceeded
364    and thus the request could not be served."""
365  pass
366
367
368class QueryTimeoutError(ServiceError):
369  """A failure due to the timeout being exceeded, but the timeout
370    was set lower than the query's expected processing time.
371    This response is distinguished from a ServiceTimeoutException
372    in that a QueryTimeoutError shows Fauna behaving in an expected manner."""
373  pass
374
375
376class ServiceInternalError(ServiceError):
377  """ServiceInternalError indicates Fauna failed unexpectedly."""
378  pass
379
380
381class ServiceTimeoutError(ServiceError):
382  """ServiceTimeoutError indicates Fauna was not available to service
383    the request before the timeout was reached."""
384  pass
class FaunaException(builtins.Exception):
7class FaunaException(Exception):
8  """Base class Fauna Exceptions"""
9  pass

Base class Fauna Exceptions

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
args
class RetryableFaunaException(FaunaException):
12class RetryableFaunaException(FaunaException):
13  pass

Base class Fauna Exceptions

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
args
class ClientError(FaunaException):
16class ClientError(FaunaException):
17  """An error representing a failure internal to the client, itself.
18    This indicates Fauna was never called - the client failed internally
19    prior to sending the request."""
20  pass

An error representing a failure internal to the client, itself. This indicates Fauna was never called - the client failed internally prior to sending the request.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
args
class NetworkError(FaunaException):
23class NetworkError(FaunaException):
24  """An error representing a failure due to the network.
25    This indicates Fauna was never reached."""
26  pass

An error representing a failure due to the network. This indicates Fauna was never reached.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
args
class ProtocolError(FaunaException):
29class ProtocolError(FaunaException):
30  """An error representing a HTTP failure - but one not directly emitted by Fauna."""
31
32  @property
33  def status_code(self) -> int:
34    return self._status_code
35
36  @property
37  def message(self) -> str:
38    return self._message
39
40  def __init__(self, status_code: int, message: str):
41    self._status_code = status_code
42    self._message = message
43
44  def __str__(self):
45    return f"{self.status_code}: {self.message}"

An error representing a HTTP failure - but one not directly emitted by Fauna.

ProtocolError(status_code: int, message: str)
40  def __init__(self, status_code: int, message: str):
41    self._status_code = status_code
42    self._message = message
status_code: int
32  @property
33  def status_code(self) -> int:
34    return self._status_code
message: str
36  @property
37  def message(self) -> str:
38    return self._message
Inherited Members
builtins.BaseException
with_traceback
args
class FaunaError(FaunaException):
 48class FaunaError(FaunaException):
 49  """Base class Fauna Errors"""
 50
 51  @property
 52  def status_code(self) -> int:
 53    return self._status_code
 54
 55  @property
 56  def code(self) -> str:
 57    return self._code
 58
 59  @property
 60  def message(self) -> str:
 61    return self._message
 62
 63  @property
 64  def abort(self) -> Optional[Any]:
 65    return self._abort
 66
 67  @property
 68  def constraint_failures(self) -> Optional[List['ConstraintFailure']]:
 69    return self._constraint_failures
 70
 71  def __init__(
 72      self,
 73      status_code: int,
 74      code: str,
 75      message: str,
 76      abort: Optional[Any] = None,
 77      constraint_failures: Optional[List['ConstraintFailure']] = None,
 78  ):
 79    self._status_code = status_code
 80    self._code = code
 81    self._message = message
 82    self._abort = abort
 83    self._constraint_failures = constraint_failures
 84
 85  def __str__(self):
 86    return f"{self.status_code}: {self.code}\n{self.message}"
 87
 88  @staticmethod
 89  def parse_error_and_throw(body: Any, status_code: int):
 90    err = body["error"]
 91    code = err["code"]
 92    message = err["message"]
 93
 94    query_tags = QueryTags.decode(
 95        body["query_tags"]) if "query_tags" in body else None
 96    stats = QueryStats(body["stats"]) if "stats" in body else None
 97    txn_ts = body["txn_ts"] if "txn_ts" in body else None
 98    schema_version = body["schema_version"] if "schema_version" in body else None
 99    summary = body["summary"] if "summary" in body else None
100
101    constraint_failures: Optional[List[ConstraintFailure]] = None
102    if "constraint_failures" in err:
103      constraint_failures = [
104          ConstraintFailure(
105              message=cf["message"],
106              name=cf["name"] if "name" in cf else None,
107              paths=cf["paths"] if "paths" in cf else None,
108          ) for cf in err["constraint_failures"]
109      ]
110
111    if status_code >= 400 and status_code < 500:
112      if code == "invalid_query":
113        raise QueryCheckError(
114            status_code=400,
115            code=code,
116            message=message,
117            summary=summary,
118            constraint_failures=constraint_failures,
119            query_tags=query_tags,
120            stats=stats,
121            txn_ts=txn_ts,
122            schema_version=schema_version,
123        )
124      elif code == "invalid_request":
125        raise InvalidRequestError(
126            status_code=400,
127            code=code,
128            message=message,
129            summary=summary,
130            constraint_failures=constraint_failures,
131            query_tags=query_tags,
132            stats=stats,
133            txn_ts=txn_ts,
134            schema_version=schema_version,
135        )
136      elif code == "abort":
137        abort = err["abort"] if "abort" in err else None
138        raise AbortError(
139            status_code=400,
140            code=code,
141            message=message,
142            summary=summary,
143            abort=abort,
144            constraint_failures=constraint_failures,
145            query_tags=query_tags,
146            stats=stats,
147            txn_ts=txn_ts,
148            schema_version=schema_version,
149        )
150      elif code == "unauthorized":
151        raise AuthenticationError(
152            status_code=401,
153            code=code,
154            message=message,
155            summary=summary,
156            constraint_failures=constraint_failures,
157            query_tags=query_tags,
158            stats=stats,
159            txn_ts=txn_ts,
160            schema_version=schema_version,
161        )
162      elif code == "forbidden" and status_code == 403:
163        raise AuthorizationError(
164            status_code=403,
165            code=code,
166            message=message,
167            summary=summary,
168            constraint_failures=constraint_failures,
169            query_tags=query_tags,
170            stats=stats,
171            txn_ts=txn_ts,
172            schema_version=schema_version,
173        )
174      elif code == "method_not_allowed":
175        raise QueryRuntimeError(
176            status_code=405,
177            code=code,
178            message=message,
179            summary=summary,
180            constraint_failures=constraint_failures,
181            query_tags=query_tags,
182            stats=stats,
183            txn_ts=txn_ts,
184            schema_version=schema_version,
185        )
186      elif code == "conflict":
187        raise ContendedTransactionError(
188            status_code=409,
189            code=code,
190            message=message,
191            summary=summary,
192            constraint_failures=constraint_failures,
193            query_tags=query_tags,
194            stats=stats,
195            txn_ts=txn_ts,
196            schema_version=schema_version,
197        )
198      elif code == "request_size_exceeded":
199        raise QueryRuntimeError(
200            status_code=413,
201            code=code,
202            message=message,
203            summary=summary,
204            constraint_failures=constraint_failures,
205            query_tags=query_tags,
206            stats=stats,
207            txn_ts=txn_ts,
208            schema_version=schema_version,
209        )
210      elif code == "limit_exceeded":
211        raise ThrottlingError(
212            status_code=429,
213            code=code,
214            message=message,
215            summary=summary,
216            constraint_failures=constraint_failures,
217            query_tags=query_tags,
218            stats=stats,
219            txn_ts=txn_ts,
220            schema_version=schema_version,
221        )
222      elif code == "time_out":
223        raise QueryTimeoutError(
224            status_code=440,
225            code=code,
226            message=message,
227            summary=summary,
228            constraint_failures=constraint_failures,
229            query_tags=query_tags,
230            stats=stats,
231            txn_ts=txn_ts,
232            schema_version=schema_version,
233        )
234      else:
235        raise QueryRuntimeError(
236            status_code=status_code,
237            code=code,
238            message=message,
239            summary=summary,
240            constraint_failures=constraint_failures,
241            query_tags=query_tags,
242            stats=stats,
243            txn_ts=txn_ts,
244            schema_version=schema_version,
245        )
246    elif status_code == 500:
247      raise ServiceInternalError(
248          status_code=status_code,
249          code=code,
250          message=message,
251          summary=summary,
252          constraint_failures=constraint_failures,
253          query_tags=query_tags,
254          stats=stats,
255          txn_ts=txn_ts,
256          schema_version=schema_version,
257      )
258    elif status_code == 503:
259      raise ServiceTimeoutError(
260          status_code=status_code,
261          code=code,
262          message=message,
263          summary=summary,
264          constraint_failures=constraint_failures,
265          query_tags=query_tags,
266          stats=stats,
267          txn_ts=txn_ts,
268          schema_version=schema_version,
269      )
270    else:
271      raise ServiceError(
272          status_code=status_code,
273          code=code,
274          message=message,
275          summary=summary,
276          constraint_failures=constraint_failures,
277          query_tags=query_tags,
278          stats=stats,
279          txn_ts=txn_ts,
280          schema_version=schema_version,
281      )

Base class Fauna Errors

FaunaError( status_code: int, code: str, message: str, abort: Optional[Any] = None, constraint_failures: Optional[List[fauna.encoding.wire_protocol.ConstraintFailure]] = None)
71  def __init__(
72      self,
73      status_code: int,
74      code: str,
75      message: str,
76      abort: Optional[Any] = None,
77      constraint_failures: Optional[List['ConstraintFailure']] = None,
78  ):
79    self._status_code = status_code
80    self._code = code
81    self._message = message
82    self._abort = abort
83    self._constraint_failures = constraint_failures
status_code: int
51  @property
52  def status_code(self) -> int:
53    return self._status_code
code: str
55  @property
56  def code(self) -> str:
57    return self._code
message: str
59  @property
60  def message(self) -> str:
61    return self._message
abort: Optional[Any]
63  @property
64  def abort(self) -> Optional[Any]:
65    return self._abort
constraint_failures: Optional[List[fauna.encoding.wire_protocol.ConstraintFailure]]
67  @property
68  def constraint_failures(self) -> Optional[List['ConstraintFailure']]:
69    return self._constraint_failures
@staticmethod
def parse_error_and_throw(body: Any, status_code: int):
 88  @staticmethod
 89  def parse_error_and_throw(body: Any, status_code: int):
 90    err = body["error"]
 91    code = err["code"]
 92    message = err["message"]
 93
 94    query_tags = QueryTags.decode(
 95        body["query_tags"]) if "query_tags" in body else None
 96    stats = QueryStats(body["stats"]) if "stats" in body else None
 97    txn_ts = body["txn_ts"] if "txn_ts" in body else None
 98    schema_version = body["schema_version"] if "schema_version" in body else None
 99    summary = body["summary"] if "summary" in body else None
100
101    constraint_failures: Optional[List[ConstraintFailure]] = None
102    if "constraint_failures" in err:
103      constraint_failures = [
104          ConstraintFailure(
105              message=cf["message"],
106              name=cf["name"] if "name" in cf else None,
107              paths=cf["paths"] if "paths" in cf else None,
108          ) for cf in err["constraint_failures"]
109      ]
110
111    if status_code >= 400 and status_code < 500:
112      if code == "invalid_query":
113        raise QueryCheckError(
114            status_code=400,
115            code=code,
116            message=message,
117            summary=summary,
118            constraint_failures=constraint_failures,
119            query_tags=query_tags,
120            stats=stats,
121            txn_ts=txn_ts,
122            schema_version=schema_version,
123        )
124      elif code == "invalid_request":
125        raise InvalidRequestError(
126            status_code=400,
127            code=code,
128            message=message,
129            summary=summary,
130            constraint_failures=constraint_failures,
131            query_tags=query_tags,
132            stats=stats,
133            txn_ts=txn_ts,
134            schema_version=schema_version,
135        )
136      elif code == "abort":
137        abort = err["abort"] if "abort" in err else None
138        raise AbortError(
139            status_code=400,
140            code=code,
141            message=message,
142            summary=summary,
143            abort=abort,
144            constraint_failures=constraint_failures,
145            query_tags=query_tags,
146            stats=stats,
147            txn_ts=txn_ts,
148            schema_version=schema_version,
149        )
150      elif code == "unauthorized":
151        raise AuthenticationError(
152            status_code=401,
153            code=code,
154            message=message,
155            summary=summary,
156            constraint_failures=constraint_failures,
157            query_tags=query_tags,
158            stats=stats,
159            txn_ts=txn_ts,
160            schema_version=schema_version,
161        )
162      elif code == "forbidden" and status_code == 403:
163        raise AuthorizationError(
164            status_code=403,
165            code=code,
166            message=message,
167            summary=summary,
168            constraint_failures=constraint_failures,
169            query_tags=query_tags,
170            stats=stats,
171            txn_ts=txn_ts,
172            schema_version=schema_version,
173        )
174      elif code == "method_not_allowed":
175        raise QueryRuntimeError(
176            status_code=405,
177            code=code,
178            message=message,
179            summary=summary,
180            constraint_failures=constraint_failures,
181            query_tags=query_tags,
182            stats=stats,
183            txn_ts=txn_ts,
184            schema_version=schema_version,
185        )
186      elif code == "conflict":
187        raise ContendedTransactionError(
188            status_code=409,
189            code=code,
190            message=message,
191            summary=summary,
192            constraint_failures=constraint_failures,
193            query_tags=query_tags,
194            stats=stats,
195            txn_ts=txn_ts,
196            schema_version=schema_version,
197        )
198      elif code == "request_size_exceeded":
199        raise QueryRuntimeError(
200            status_code=413,
201            code=code,
202            message=message,
203            summary=summary,
204            constraint_failures=constraint_failures,
205            query_tags=query_tags,
206            stats=stats,
207            txn_ts=txn_ts,
208            schema_version=schema_version,
209        )
210      elif code == "limit_exceeded":
211        raise ThrottlingError(
212            status_code=429,
213            code=code,
214            message=message,
215            summary=summary,
216            constraint_failures=constraint_failures,
217            query_tags=query_tags,
218            stats=stats,
219            txn_ts=txn_ts,
220            schema_version=schema_version,
221        )
222      elif code == "time_out":
223        raise QueryTimeoutError(
224            status_code=440,
225            code=code,
226            message=message,
227            summary=summary,
228            constraint_failures=constraint_failures,
229            query_tags=query_tags,
230            stats=stats,
231            txn_ts=txn_ts,
232            schema_version=schema_version,
233        )
234      else:
235        raise QueryRuntimeError(
236            status_code=status_code,
237            code=code,
238            message=message,
239            summary=summary,
240            constraint_failures=constraint_failures,
241            query_tags=query_tags,
242            stats=stats,
243            txn_ts=txn_ts,
244            schema_version=schema_version,
245        )
246    elif status_code == 500:
247      raise ServiceInternalError(
248          status_code=status_code,
249          code=code,
250          message=message,
251          summary=summary,
252          constraint_failures=constraint_failures,
253          query_tags=query_tags,
254          stats=stats,
255          txn_ts=txn_ts,
256          schema_version=schema_version,
257      )
258    elif status_code == 503:
259      raise ServiceTimeoutError(
260          status_code=status_code,
261          code=code,
262          message=message,
263          summary=summary,
264          constraint_failures=constraint_failures,
265          query_tags=query_tags,
266          stats=stats,
267          txn_ts=txn_ts,
268          schema_version=schema_version,
269      )
270    else:
271      raise ServiceError(
272          status_code=status_code,
273          code=code,
274          message=message,
275          summary=summary,
276          constraint_failures=constraint_failures,
277          query_tags=query_tags,
278          stats=stats,
279          txn_ts=txn_ts,
280          schema_version=schema_version,
281      )
Inherited Members
builtins.BaseException
with_traceback
args
class ServiceError(FaunaError, fauna.encoding.wire_protocol.QueryInfo):
284class ServiceError(FaunaError, QueryInfo):
285  """An error representing a query failure returned by Fauna."""
286
287  def __init__(
288      self,
289      status_code: int,
290      code: str,
291      message: str,
292      summary: Optional[str] = None,
293      abort: Optional[Any] = None,
294      constraint_failures: Optional[List['ConstraintFailure']] = None,
295      query_tags: Optional[Mapping[str, str]] = None,
296      stats: Optional[QueryStats] = None,
297      txn_ts: Optional[int] = None,
298      schema_version: Optional[int] = None,
299  ):
300    QueryInfo.__init__(
301        self,
302        query_tags=query_tags,
303        stats=stats,
304        summary=summary,
305        txn_ts=txn_ts,
306        schema_version=schema_version,
307    )
308
309    FaunaError.__init__(
310        self,
311        status_code=status_code,
312        code=code,
313        message=message,
314        abort=abort,
315        constraint_failures=constraint_failures,
316    )
317
318  def __str__(self):
319    constraint_str = "---"
320    if self._constraint_failures:
321      constraint_str = f"---\nconstraint failures: {self._constraint_failures}\n---"
322
323    return f"{self._status_code}: {self.code}\n{self.message}\n{constraint_str}\n{self.summary or ''}"

An error representing a query failure returned by Fauna.

ServiceError( status_code: int, code: str, message: str, summary: Optional[str] = None, abort: Optional[Any] = None, constraint_failures: Optional[List[fauna.encoding.wire_protocol.ConstraintFailure]] = None, query_tags: Optional[Mapping[str, str]] = None, stats: Optional[fauna.encoding.wire_protocol.QueryStats] = None, txn_ts: Optional[int] = None, schema_version: Optional[int] = None)
287  def __init__(
288      self,
289      status_code: int,
290      code: str,
291      message: str,
292      summary: Optional[str] = None,
293      abort: Optional[Any] = None,
294      constraint_failures: Optional[List['ConstraintFailure']] = None,
295      query_tags: Optional[Mapping[str, str]] = None,
296      stats: Optional[QueryStats] = None,
297      txn_ts: Optional[int] = None,
298      schema_version: Optional[int] = None,
299  ):
300    QueryInfo.__init__(
301        self,
302        query_tags=query_tags,
303        stats=stats,
304        summary=summary,
305        txn_ts=txn_ts,
306        schema_version=schema_version,
307    )
308
309    FaunaError.__init__(
310        self,
311        status_code=status_code,
312        code=code,
313        message=message,
314        abort=abort,
315        constraint_failures=constraint_failures,
316    )
class AbortError(ServiceError):
326class AbortError(ServiceError):
327  pass

An error representing a query failure returned by Fauna.

class InvalidRequestError(ServiceError):
330class InvalidRequestError(ServiceError):
331  pass

An error representing a query failure returned by Fauna.

class QueryCheckError(ServiceError):
334class QueryCheckError(ServiceError):
335  """An error due to a "compile-time" check of the query failing."""
336  pass

An error due to a "compile-time" check of the query failing.

class ContendedTransactionError(ServiceError):
339class ContendedTransactionError(ServiceError):
340  """Transaction is aborted due to concurrent modification."""
341  pass

Transaction is aborted due to concurrent modification.

class QueryRuntimeError(ServiceError):
344class QueryRuntimeError(ServiceError):
345  """An error response that is the result of the query failing during execution.
346    QueryRuntimeError's occur when a bug in your query causes an invalid execution
347    to be requested.
348    The 'code' field will vary based on the specific error cause."""
349  pass

An error response that is the result of the query failing during execution. QueryRuntimeError's occur when a bug in your query causes an invalid execution to be requested. The 'code' field will vary based on the specific error cause.

class AuthenticationError(ServiceError):
352class AuthenticationError(ServiceError):
353  """AuthenticationError indicates invalid credentials were used."""
354  pass

AuthenticationError indicates invalid credentials were used.

class AuthorizationError(ServiceError):
357class AuthorizationError(ServiceError):
358  """AuthorizationError indicates the credentials used do not have
359    permission to perform the requested action."""
360  pass

AuthorizationError indicates the credentials used do not have permission to perform the requested action.

class ThrottlingError(ServiceError, RetryableFaunaException):
363class ThrottlingError(ServiceError, RetryableFaunaException):
364  """ThrottlingError indicates some capacity limit was exceeded
365    and thus the request could not be served."""
366  pass

ThrottlingError indicates some capacity limit was exceeded and thus the request could not be served.

class QueryTimeoutError(ServiceError):
369class QueryTimeoutError(ServiceError):
370  """A failure due to the timeout being exceeded, but the timeout
371    was set lower than the query's expected processing time.
372    This response is distinguished from a ServiceTimeoutException
373    in that a QueryTimeoutError shows Fauna behaving in an expected manner."""
374  pass

A failure due to the timeout being exceeded, but the timeout was set lower than the query's expected processing time. This response is distinguished from a ServiceTimeoutException in that a QueryTimeoutError shows Fauna behaving in an expected manner.

class ServiceInternalError(ServiceError):
377class ServiceInternalError(ServiceError):
378  """ServiceInternalError indicates Fauna failed unexpectedly."""
379  pass

ServiceInternalError indicates Fauna failed unexpectedly.

class ServiceTimeoutError(ServiceError):
382class ServiceTimeoutError(ServiceError):
383  """ServiceTimeoutError indicates Fauna was not available to service
384    the request before the timeout was reached."""
385  pass

ServiceTimeoutError indicates Fauna was not available to service the request before the timeout was reached.