tempest_fastapi_sdk.exceptions¶
A hierarquia AppException, as exceções por domínio e os handlers que as viram resposta HTTP.
AppException
¶
AppException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: HTTPException
Base exception for all application-level errors.
Concrete projects raise a domain-specific subclass that declares its
code (and status_code, when the parent's is wrong) in the
class body, and uses __init__ only to build message /
details::
class CategoryInUseException(ConflictException):
"""Raised when deleting a category services still reference."""
code = "CATEGORY_IN_USE"
def __init__(self, category_id: str) -> None:
"""Initialize the exception.
Args:
category_id (str): The category that cannot be deleted.
"""
super().__init__(
message="Cannot delete a category that still has services.",
details={"category_id": category_id},
)
The class-body form is the documented one because it is the only
introspectable one. Passing code= at the raise site works
identically at runtime, but hides the real value from every static
consumer: CategoryInUseException.code would answer the inherited
"CONFLICT" and only CategoryInUseException("x").code would
answer "CATEGORY_IN_USE". Since reading it would then require
instantiating — which means knowing each __init__ signature —
tooling that documents the errors a route can raise
(:func:tempest_fastapi_sdk.error_responses) cannot work at all.
A subclass that declares no code of its own warns with
:class:InheritedErrorCodeWarning.
The matching exception handler (see
:mod:tempest_fastapi_sdk.api.handlers) emits the JSON shape
described by
:class:tempest_fastapi_sdk.schemas.errors.ErrorResponseSchema::
{
"detail": "<message>",
"code": "<code>",
"details": {"<any>": "<context>"},
"field": "<input name>"
}
field names the input the failure is about, and is emitted
only when the exception declares one. A 422 already answers this
through loc; a 409 or a 401 over the same input did not, so the
client re-derived the mapping at the call site ("a CONFLICT in
the signup form means the e-mail, because that form has only one
possible conflict"). The key stays absent rather than null, so
"field" in body keeps meaning there is a culprit input.
Security
Leave field unset on invalid credentials. Naming email
there confirms the address exists, and naming password
confirms the same by omission — it turns the response into an
account-enumeration oracle, which is the whole reason the
message is generic.
Class attributes (defaults the constructor falls back to):
status_code (int): HTTP status code.
message (str): Default human-readable message.
code (str): Stable, machine-readable identifier.
details_example (dict[str, Any]): Representative details
payload, used only to build the OpenAPI example — never
read at runtime. Declare it when the exception attaches
context worth showing to a frontend developer.
field (str | None): Name of the input this failure is about,
emitted at the top of the envelope. None (the default)
keeps the key out of the body entirely.
log_level (int | None): Severity the exception handler logs this
exception at, for a response that is expected rather than a
failure. None (the default) keeps the handler's rule:
INFO for 4xx, and for 5xx the handler's log_level with
a traceback, the http_500 marker that routes the record to
500.log and the admin's "500" source, and the
on_server_error callback. A declared level replaces all of
that: the record is logged at it, without a traceback, without
the marker, and on_server_error is not called. The status
code and the envelope do not change.
:class:~tempest_fastapi_sdk.IntegrationDisabledException
declares logging.WARNING (an integration switched off by
configuration answers 503 by design), and so does
:class:~tempest_fastapi_sdk.EmailDeliveryException, whose SMTP
failure the mailer already logged at ERROR.
Instance attributes
status_code (int): The status code attached to this instance.
code (str): The error code attached to this instance.
message (str): The message attached to this instance — the one
passed to the constructor, falling back to the class-level
default. Kept in sync with detail so a caught exception
reports what was raised, not the class default.
details (dict[str, Any]): Free-form context attached to the
response payload.
message_key (str | None): Catalog key used to localize the
detail when a MessageCatalog is registered. None
falls back to code at resolution time.
message_params (dict[str, Any]): Values interpolated into the
localized template via :meth:str.format.
field (str | None): The input this instance blames, falling back
to the class-level default.
Localization
When :func:register_exception_handlers is given a catalog,
the handler resolves message_key (or code) against the
request's negotiated locale and replaces detail with the
localized string. Without a catalog the behavior is unchanged —
detail is the literal message.
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str | None
|
Override the class-level message. Used
verbatim as |
None
|
code
|
str | None
|
Override the class-level error code on this instance only — leaves other instances of the same class untouched. |
None
|
status_code
|
int | None
|
Override the class-level HTTP status code on this instance only. |
None
|
details
|
dict[str, Any] | None
|
Structured context to attach to the JSON response. |
None
|
headers
|
dict[str, str] | None
|
Optional HTTP headers to include in the response. |
None
|
message_key
|
str | None
|
Catalog key to localize against.
Defaults to the class-level |
None
|
message_params
|
dict[str, Any] | None
|
Values interpolated into the localized message template. |
None
|
field
|
str | None
|
Name of the input this failure is about
— the form control a client should highlight. Defaults
to the class-level |
None
|
InheritedErrorCodeWarning
¶
Bases: UserWarning
Warns that a subclass silently inherited a generic code.
Emitted at class-creation time by
:meth:AppException.__init_subclass__ when a subclass declares
neither code nor message_key and therefore answers with one
of the SDK's generic identifiers ("CONFLICT", "NOT_FOUND",
…). Clients cannot tell such a failure apart from any other with the
same status, and OpenAPI tooling cannot document it — see
:func:tempest_fastapi_sdk.error_responses.
Silence it per-project when the pattern is deliberate::
import warnings
from tempest_fastapi_sdk import InheritedErrorCodeWarning
warnings.filterwarnings("ignore", category=InheritedErrorCodeWarning)
NotFoundException
¶
NotFoundException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when a single resource cannot be located.
Use for get_by_id / get_by_email style lookups. NEVER use
for collection endpoints — those should return [] instead.
ConflictException
¶
ConflictException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when a write would violate a uniqueness/integrity rule.
Typically surfaced by the repository when SQLAlchemy raises an
IntegrityError on insert/update.
not_found_exception
¶
not_found_exception(
code: str,
*,
subject: str = "Resource",
field: str = "id",
template: str = DEFAULT_NOT_FOUND_TEMPLATE,
template_anonymous: str = DEFAULT_NOT_FOUND_TEMPLATE_ANONYMOUS,
name: str | None = None,
) -> type[NotFoundException]
Build a domain-specific 404 exception class.
The returned class is a real
:class:~tempest_fastapi_sdk.exceptions.NotFoundException subclass —
it declares code in its body, so
:func:~tempest_fastapi_sdk.error_responses documents it and no
:class:~tempest_fastapi_sdk.InheritedErrorCodeWarning is raised —
and it accepts both call shapes::
BudgetNotFoundException = not_found_exception(
"BUDGET_NOT_FOUND",
subject="Orcamento",
field="budget_id",
)
BudgetNotFoundException("abc").detail
# 'Orcamento abc not found.'
BudgetNotFoundException("abc").details
# {'budget_id': 'abc'}
BudgetNotFoundException(message="Nao encontrado.").detail
# 'Nao encontrado.'
Accepting message= is not cosmetic: BaseRepository raises
self.not_found_exception(message=...), so a hand-written class
whose __init__ takes only the id answers every repository miss
with a TypeError — a 500 instead of a 404.
Localize by keying a
:class:~tempest_fastapi_sdk.exceptions.MessageCatalog on code,
or by writing the templates in the project's language.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
Stable machine-readable identifier, e.g.
|
required |
subject
|
str
|
Human-readable name of the resource, interpolated
as |
'Resource'
|
field
|
str
|
Key the identifier is filed under in |
'id'
|
template
|
str
|
Message template used when an identifier is
given. Receives |
DEFAULT_NOT_FOUND_TEMPLATE
|
template_anonymous
|
str
|
Message template used when it is not.
Receives |
DEFAULT_NOT_FOUND_TEMPLATE_ANONYMOUS
|
name
|
str | None
|
Class name. Defaults to the code in
PascalCase plus |
None
|
Returns:
| Type | Description |
|---|---|
type[NotFoundException]
|
type[NotFoundException]: The generated exception class. |
conflict_exception
¶
conflict_exception(
code: str,
*,
subject: str = "Resource",
field: str = "id",
template: str = DEFAULT_CONFLICT_TEMPLATE,
template_anonymous: str = DEFAULT_CONFLICT_TEMPLATE_ANONYMOUS,
name: str | None = None,
) -> type[ConflictException]
Build a domain-specific 409 exception class.
The 409 twin of :func:not_found_exception, for the same reason:
BaseRepository raises its conflict classes as
exception_class(message=...) too, from the
create_conflict_exception / update_conflict_exception slots::
EmailTakenException = conflict_exception(
"EMAIL_TAKEN",
subject="Email",
field="email",
template="{identifier} is already registered.",
)
repository = UserRepository(
session,
create_conflict_exception=EmailTakenException,
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
Stable machine-readable identifier. |
required |
subject
|
str
|
Human-readable name of the resource. |
'Resource'
|
field
|
str
|
Key the identifier is filed under in |
'id'
|
template
|
str
|
Message template used with an identifier. |
DEFAULT_CONFLICT_TEMPLATE
|
template_anonymous
|
str
|
Message template used without one. |
DEFAULT_CONFLICT_TEMPLATE_ANONYMOUS
|
name
|
str | None
|
Class name. Defaults to the code in
PascalCase plus |
None
|
Returns:
| Type | Description |
|---|---|
type[ConflictException]
|
type[ConflictException]: The generated exception class. |
UnauthorizedException
¶
UnauthorizedException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when the caller is not authenticated.
Use for missing/invalid/expired credentials. For "authenticated
but not allowed" cases, use
:class:tempest_fastapi_sdk.exceptions.forbidden.ForbiddenException.
ForbiddenException
¶
MFARequiredException
¶
MFARequiredException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: ForbiddenException
Raised when a route needs a second factor the session never proved.
The token is valid and the user is known, so the answer is 403 and
not 401: logging in again with the password alone would not help.
The client completes the two-step login (/auth/mfa/verify) and
retries with the token that comes out of it.
ValidationException
¶
ValidationException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when input fails a business rule beyond Pydantic.
Pydantic emits 422 automatically for schema validation; use this for downstream rules that only the service layer can enforce.
OrderByNotAllowedException
¶
Bases: ValidationException
Raised when order_by names a column the listing does not sort by.
Sorting is an oracle. A caller who controls one row learns another
row's value by binary search over where their own row lands, and a
caller who controls nothing still ranks every row by the column —
ordering users by wallet or hashed_password leaks both.
details["allowed"] carries only the set the listing declared
(orderable_columns on the filter schema or on the repository),
sorted. When no set was declared the key is absent: the repository
does not know which listing called it, and the full mapper column
list is exactly the map of what to try that the refusal must never
publish.
Subclasses :class:ValidationException, so except
ValidationException keeps catching it; only the code is new.
Attributes:
| Name | Type | Description |
|---|---|---|
order_by |
str
|
The rejected value, as the caller sent it. |
Initialize the refusal with the rejected column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order_by
|
str
|
The |
required |
allowed
|
Iterable[str] | None
|
The columns the listing
sorts by. |
None
|
PageSizeTooLargeException
¶
Bases: ValidationException
Raised when a repository is asked for a page above its ceiling.
Raised by :class:~tempest_fastapi_sdk.BaseRepository when the
repository declares max_page_size and page_size (or the cursor
limit) exceeds it. The filter schemas enforce their own ceiling as
a regular pydantic less_than_equal error, so this is the second
line for callers that reach the repository without one.
Attributes:
| Name | Type | Description |
|---|---|---|
page_size |
int
|
The requested page size. |
max_page_size |
int
|
The ceiling it exceeded. |
Initialize the refusal with the requested size and the ceiling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page_size
|
int
|
The page size the caller asked for. |
required |
max_page_size
|
int
|
The ceiling the repository declares. |
required |
PushEndpointNotPublicException
¶
PushEndpointNotPublicException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: ValidationException
Raised when a push subscription names an endpoint delivery would refuse.
The Web Push dispatcher only contacts endpoints that are https and
resolve to public addresses (unless it was built with
allow_private_networks=True). An endpoint pointing inside the
server's own network is refused at registration with this exception
instead of being stored and refused on every send.
details is empty on purpose: which address the host resolved to is
exactly what a caller probing the internal network wants to learn.
Subclasses :class:ValidationException, so except
ValidationException keeps catching it and the HTTP status is 422.
UnknownFilterKeyException
¶
Bases: ValidationException
Raised when a filters key names no column or no operator.
A repository filters mapping is column name to value, with an
optional <column>__<op> suffix. A key the model has no column
for — a typo such as {"usr_id": 1234} — or a suffix that is not a
known operator — {"user_id__bogus": 1} — used to be dropped from
the query in silence. On a read that returned every row; on
bulk_update / delete_many it changed every row in the table,
because the mapping was not empty and so the empty-filter guard never
fired. The key is now refused before any statement runs.
details["filter"] carries the rejected key only. The model's
column list is deliberately absent: when the mapping comes from a
query string, that list is a map of what to probe.
Subclasses :class:ValidationException, so except
ValidationException keeps catching it and the HTTP status is 422.
Attributes:
| Name | Type | Description |
|---|---|---|
filter_key |
str
|
The rejected key, as the caller sent it. |
Initialize the refusal with the rejected key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_key
|
str
|
The |
required |
InvalidFilterValueException
¶
Bases: ValidationException
Raised when a filters value cannot express its operator.
A suffix operator fixes the shape its value must have: between
needs an ordered two-item (lo, hi) list / tuple. A value
that did not fit used to be dropped in silence, and the condition
vanishing from the WHERE widened the statement instead of
narrowing it — on bulk_update / delete_many /
update_returning that meant touching every row the filter did
not name (measured on SQLite, #484). The value is now refused
before any statement runs. The in family is not refused on a
scalar: a single value is wrapped in a one-item list ({"status__in":
"open"} → IN ('open')), which is what the caller asked for.
details["filter"] carries the rejected key (suffix included) and
details["value"] a bounded repr of the value — enough to spot
the mistake without echoing a whole payload.
Subclasses :class:ValidationException, so except
ValidationException keeps catching it and the HTTP status is 422.
Attributes:
| Name | Type | Description |
|---|---|---|
filter_key |
str
|
The rejected key, as the caller sent it. |
value |
Any
|
The rejected value, as the caller sent it. |
Initialize the refusal with the rejected key and value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_key
|
str
|
The full |
required |
value
|
Any
|
The value that cannot express the operator. |
required |
ValidationValueError
¶
Bases: ValueError
A ValueError that names its catalog key.
Pydantic files everything a field validator raises under the single
error type value_error, with the exception itself in
ctx["error"]. The catalog localizes by error type, so every
message the SDK's own BR validators wrote — invalid CPF/CNPJ,
invalid CEP, invalid PIX key — reached the client in English
inside a Portuguese template::
Valor inválido: invalid CPF/CNPJ
A consumer could not fix that from outside: the only key the six
cases share is VALIDATION.value_error, so translating them meant
matching substrings of the SDK's English phrases — an
unannounced coupling that breaks silently the day a phrase is
reworded.
Raising this instead attaches a stable code the validation
handler resolves as VALIDATION.<code>, falling back to
VALIDATION.value_error when the catalog does not know it. A
plain ValueError raised by a consumer's own validator keeps
behaving exactly as before.
Attributes:
| Name | Type | Description |
|---|---|---|
code |
str
|
Catalog key suffix, |
params |
dict[str, Any]
|
Values interpolated into the localized
template, merged over pydantic's own |
Initialize the error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
Catalog key suffix resolved under
|
required |
message
|
str
|
The English phrase, kept as |
required |
params
|
Mapping[str, Any] | None
|
Template values for the localized message. |
None
|
TooManyRequestsException
¶
TooManyRequestsException(
message: str | None = None,
*,
retry_after_seconds: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
)
Bases: AppException
Raised when a client exceeds a rate limit or attempt budget.
Carries an optional Retry-After header (seconds) and mirrors
the same value under details["retry_after_seconds"] so clients
can back off without parsing headers. Used by
:class:tempest_fastapi_sdk.utils.AttemptThrottle and suitable for
any throttled flow (login, OTP, code verification).
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str | None
|
Override the class-level message. |
None
|
retry_after_seconds
|
int | None
|
Cooldown in seconds. When
given, sets the |
None
|
details
|
dict[str, Any] | None
|
Structured context. |
None
|
headers
|
dict[str, str] | None
|
Extra response headers;
merged with the |
None
|
IntegrationDisabledException
¶
Bases: AppException
Raised when code uses an integration its <NAME>_ENABLED turned off.
A deployment that ships in phases boots with some third-party
integrations not configured yet (STORAGE_ENABLED=false,
EMAIL_ENABLED=false, FIREBASE_ENABLED=false). The production
guard skips them, and every SDK client built from those settings
answers each operation with this exception instead of talking to a
server that was never set up — so the failure is the same 503 with
the same code everywhere, never a silent no-op and never a
connection error against a development default.
The integration name in details["integration"] is the same string
:meth:~tempest_fastapi_sdk.settings.BaseAppSettings.disabled_integrations
lists ("storage", "email", "firebase", "revenuecat").
Logged at WARNING, without a traceback and outside 500.log
(log_level): the 503 is the configured answer, not a failure.
Logged as a 5xx error, eight of eleven records in one service's "500"
source were this exception, with storage and AI switched off, and the
one real bug was buried among them.
Attributes:
| Name | Type | Description |
|---|---|---|
integration |
str
|
The integration that refused the call. |
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
integration
|
str
|
Name of the disabled integration, as listed
by |
required |
message
|
str | None
|
Override the message. |
None
|
EmailDeliveryException
¶
EmailDeliveryException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when the SMTP server could not take a message.
:meth:~tempest_fastapi_sdk.EmailUtils.send raises it for every
transport failure: the host does not resolve, the connection is
refused or times out, the TLS handshake fails (SMTP_USE_SSL=true
against the STARTTLS port 587 answers [SSL:
WRONG_VERSION_NUMBER]), the server rejects the login, or it refuses
the message. The original error is chained as __cause__, so code
that needs the SMTP reply code still reaches it.
The response carries no details: the host, the port and the
recipient are server-side facts, and the client can only retry later.
They are logged once, at ERROR, by the mailer that raised — which
is why the exception handler logs it at WARNING without a traceback
(log_level): a second ERROR record with a traceback reported
the same outage twice.
It is not :class:IntegrationDisabledException: that one means the
deployment chose to run without e-mail, this one means e-mail is
configured and failed.
ZapSendFailedException
¶
Bases: AppException
Raised when the zap-api 202 answers a key whose send already failed.
:meth:~tempest_fastapi_sdk.integrations.messaging.zap.ZapInbox.send_text
raises it when the 202 carries status="failed". A fresh send never
answers that: the gateway enqueues every new row as queued. It only
comes back as the deduped=True answer to a key whose outbox row the
gateway's worker already marked failed — read in the gateway's
outbound-submit.ts and outbox repository, not measured against a
running gateway. It is a 502 because the failure is the downstream
gateway's, not the caller's request.
details["idempotency_key"] names that send. Reusing the key returns
the same failed row again, so a real retry needs a fresh key.
Attributes:
| Name | Type | Description |
|---|---|---|
idempotency_key |
str
|
The key the refused send went out with. |
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idempotency_key
|
str
|
The key the refused send went out with. |
required |
GoogleDriveException
¶
GoogleDriveException(
*, upstream_status: int | None, reason: str | None, message: str | None = None
)
Bases: AppException
Raised when Google Drive, or Google's token endpoint, refuses a call.
The Google Drive upload backend
(:mod:tempest_fastapi_sdk.integrations.storage.google_drive) raises
it for every non-success answer it does not retry, and once its retries
for 429/5xx are spent. details carries what the upstream
said: the HTTP status in details["status"] (None when the server
was never reached) and the first error.errors[].reason of a Drive
error body — or the OAuth error of the token endpoint, such as
invalid_grant — in details["reason"].
It is a 502: the request reached the service fine, the storage
behind it did not take it. Neither the access token, the signed
assertion nor the private key ever appears in the message.
Attributes:
| Name | Type | Description |
|---|---|---|
upstream_status |
int | None
|
Google's HTTP status, or |
reason |
str | None
|
Google's machine-readable reason. |
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
upstream_status
|
int | None
|
Google's HTTP status, or |
required |
reason
|
str | None
|
Google's reason string, when the body had one. |
required |
message
|
str | None
|
Override the message. Already redacted by the caller when it quotes an upstream body. |
None
|
GoogleDriveFolderNotFoundException
¶
Bases: GoogleDriveException
Raised when the configured Drive folder answers 404.
Drive answers 404 notFound both for a folder id that does not
exist and for one the service account cannot see, so the message says
what to do about the second, more common case: share the folder (or
add the account as a member of the Shared Drive) with the service
account's client_email.
Attributes:
| Name | Type | Description |
|---|---|---|
folder_id |
str
|
The folder the backend writes into. |
principal_email |
str | None
|
The account the folder must be shared with, when known. |
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder_id
|
str
|
The configured folder id. |
required |
principal_email
|
str | None
|
The service account's
|
required |
GooglePlacesException
¶
GooglePlacesException(
*,
upstream_status: int | None = None,
reason: str | None = None,
message: str | None = None,
)
Bases: AppException
Raised when the Google Places API (New) v1 refuses a request or fails.
:class:~tempest_fastapi_sdk.integrations.places.google_places.GooglePlacesClient
raises this for non-2xx responses (except 404 on detail/website lookups,
which returns None), transport or timeout failures, circuit breaker
rejections, and malformed JSON payloads.
It maps to HTTP 502 because the downstream Google Places API refused
or could not fulfill the request. API keys are never included in messages
or details, and upstream error text is redacted before being surfaced.
Attributes:
| Name | Type | Description |
|---|---|---|
upstream_status |
int | None
|
Google's HTTP status code, or |
reason |
str | None
|
Machine-readable error status or reason extracted from the upstream Google error envelope or transport failure. |
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
upstream_status
|
int | None
|
Google Places HTTP status code, or
|
None
|
reason
|
str | None
|
Machine-readable error status or reason, when available. |
None
|
message
|
str | None
|
Optional message override, already redacted when quoting upstream text. |
None
|
ApifyRequestException
¶
ApifyRequestException(
*,
upstream_status: int | None = None,
actor_id: str | None = None,
detail: str | None = None,
message: str | None = None,
)
Bases: AppException
Raised when an Apify actor request fails over HTTP or returns invalid data.
:class:~tempest_fastapi_sdk.integrations.scraping.apify.ApifyClient
raises this for every non-2xx answer, network or timeout failure, circuit
breaker rejection, and malformed JSON payload instead of swallowing the
failure into an empty list. Callers can then decide whether to retry,
record a per-item error, or abort a batch.
It maps to HTTP 502 because the downstream Apify API refused or could
not complete the request. The API token is never placed in URLs or error
messages.
Attributes:
| Name | Type | Description |
|---|---|---|
upstream_status |
int | None
|
Apify's HTTP status code, or |
actor_id |
str | None
|
The normalized actor identifier that was called. |
upstream_detail |
str | None
|
Short machine- or human-readable detail
extracted from the upstream response or transport error. Also
stored in |
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
upstream_status
|
int | None
|
Apify's HTTP status code, or |
None
|
actor_id
|
str | None
|
Normalized actor identifier invoked. |
None
|
detail
|
str | None
|
Short error detail from the response or
transport failure. Stored in |
None
|
message
|
str | None
|
Optional message override. |
None
|
LinkedInApiException
¶
LinkedInApiException(
*,
upstream_status: int | None,
reason: str | None = None,
service_error_code: int | None = None,
retry_after: float | None = None,
message: str | None = None,
)
Bases: AppException
Raised when LinkedIn's API or OAuth endpoint refuses a call.
:mod:tempest_fastapi_sdk.integrations.social.linkedin raises this
hierarchy for every non-2xx or transport failure. details carries
the upstream HTTP status in details["status"] (None when the
request never reached LinkedIn) and a machine-readable classification
or upstream error code in details["reason"]. When LinkedIn returns
a numeric serviceErrorCode or a Retry-After header, they are
attached as details["service_error_code"] and
details["retry_after"] respectively.
It answers 502 because the caller's request reached this service
fine and the downstream social API failed. Access tokens and client
secrets never appear in the message or details.
Attributes:
| Name | Type | Description |
|---|---|---|
upstream_status |
int | None
|
LinkedIn's HTTP status, or |
reason |
str | None
|
Classification or upstream error code. |
service_error_code |
int | None
|
LinkedIn's |
retry_after |
float | None
|
Seconds from the |
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
upstream_status
|
int | None
|
LinkedIn's HTTP status, or
|
required |
reason
|
str | None
|
Machine-readable classification or upstream error code. |
None
|
service_error_code
|
int | None
|
LinkedIn's numeric
|
None
|
retry_after
|
float | None
|
Numeric |
None
|
message
|
str | None
|
Optional human-readable override. |
None
|
LinkedInUnauthorizedException
¶
LinkedInUnauthorizedException(
*,
reason: str | None = "unauthorized",
service_error_code: int | None = None,
message: str | None = None,
)
Bases: LinkedInApiException
Raised when LinkedIn answers 401 (invalid or expired token).
Subclasses :class:LinkedInApiException, so except
LinkedInApiException still catches it. Keeps status_code = 502
rather than 401 so a downstream LinkedIn token expiration is not
mistaken by the end user's client for their own session expiring.
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reason
|
str | None
|
Upstream error code or |
'unauthorized'
|
service_error_code
|
int | None
|
LinkedIn's numeric
|
None
|
message
|
str | None
|
Optional human-readable override. |
None
|
LinkedInForbiddenException
¶
LinkedInForbiddenException(
*,
reason: str | None = "forbidden",
service_error_code: int | None = None,
message: str | None = None,
)
Bases: LinkedInApiException
Raised when LinkedIn answers 403 (missing scope or permission).
Typical causes are publishing on behalf of an organization without
w_organization_social approved, or posting to an author URN the
token owner cannot administer.
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reason
|
str | None
|
Upstream error code or |
'forbidden'
|
service_error_code
|
int | None
|
LinkedIn's numeric
|
None
|
message
|
str | None
|
Optional human-readable override. |
None
|
LinkedInRateLimitException
¶
LinkedInRateLimitException(
*,
reason: str | None = "rate_limited",
service_error_code: int | None = None,
retry_after: float | None = None,
message: str | None = None,
)
Bases: LinkedInApiException
Raised when LinkedIn answers 429 (rate limit exceeded).
Answers 503 to signal a transient upstream throttle; when LinkedIn
supplies a numeric Retry-After header, it is preserved in
:attr:retry_after and details["retry_after"].
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reason
|
str | None
|
Upstream error code or |
'rate_limited'
|
service_error_code
|
int | None
|
LinkedIn's numeric
|
None
|
retry_after
|
float | None
|
Numeric |
None
|
message
|
str | None
|
Optional human-readable override. |
None
|
GmapsScraperJobError
¶
GmapsScraperJobError(
*,
job_id: str | None = None,
status: str | None = None,
reason: str | None = None,
message: str | None = None,
)
Bases: AppException
Raised when a gosom/google-maps-scraper job fails or times out.
:meth:~tempest_fastapi_sdk.integrations.places.gmaps_scraper.GmapsScraperClient.scrape
raises this error when the sidecar reports status="failed", returns an
incomplete job response, or does not finish within wait_seconds. It is
a 502 because the failure belongs to the downstream scraper sidecar,
not to the caller's request.
Attributes:
| Name | Type | Description |
|---|---|---|
job_id |
str | None
|
Sidecar job identifier, when known. |
status |
str | None
|
Last job status observed (for example
|
reason |
str | None
|
Short machine- or operator-readable failure
detail from the sidecar, or |
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str | None
|
Sidecar job identifier, when known. |
None
|
status
|
str | None
|
Last status reported by the sidecar. |
None
|
reason
|
str | None
|
Failure reason or |
None
|
message
|
str | None
|
Override the default human-readable message. |
None
|
StorageIntegrityException
¶
Bases: AppException
Raised when an encrypted object cannot be authenticated or parsed.
:class:~tempest_fastapi_sdk.storage.LocalObjectStorageClient, built
with encryption_keys, raises it instead of returning bytes it could
not authenticate: a block whose tag does not verify (wrong key, a byte
changed on disk, a block moved, a file copied to another key), a file
cut short, a header it cannot parse, a key id it does not hold, or a
plaintext file while allow_plaintext_read is off.
It is a 500: the request was fine, the stored object is not. The
response carries details["reason"] only — never the bucket, the key
or any byte of the file — and the handler logs it like any other server
error.
Attributes:
| Name | Type | Description |
|---|---|---|
reason |
str
|
|
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reason
|
str
|
Which check failed — |
required |
message
|
str | None
|
Override the message, for the log. It is never built from the object's name or contents. |
None
|
PresignedUrlUnsupportedException
¶
Bases: AppException
Raised by an upload backend that cannot mint a presigned URL.
presigned_url on a backend whose store has no such thing — Google
Drive serves files by id to callers holding a Drive permission, never
through a temporary signed link — raises it instead of returning a
permanent link that a caller would treat as one that expires. Serve the
file through your own authenticated download route instead.
It is a 501: the operation is not implemented by the configured
backend, whatever the request.
Attributes:
| Name | Type | Description |
|---|---|---|
backend |
str
|
The backend that refused, such as |
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
str
|
Name of the backend that refused. |
required |
message
|
str | None
|
Override the message. |
None
|
InvalidTokenException
¶
ExpiredTokenException
¶
InvalidSignedURLException
¶
InvalidSignedURLException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: ForbiddenException
Raised when a signed URL is missing its parameters or fails the MAC.
Covers every way the signature can be wrong: absent or malformed
expires/signature, a tampered path or expires, a different
purpose or a different secret. They are deliberately not told apart,
so the response leaks nothing about which part was rejected.
ExpiredSignedURLException
¶
ExpiredSignedURLException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: ForbiddenException
Raised when an authentic signed URL is past its expires instant.
Only raised after the signature verified, so it never fires for a forged
expires — that one is :class:InvalidSignedURLException.
OAuthProviderNotConfiguredException
¶
OAuthProviderNotConfiguredException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: NotFoundException
Raised when {provider} names no registered client.
The provider key is part of the path, so an unregistered one is an unknown route rather than a bad request.
OAuthProviderDeniedException
¶
OAuthProviderDeniedException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: UnauthorizedException
Raised when the provider returned error= instead of a code.
Almost always the user declining the consent screen, which is a normal outcome and deserves a different message from a failure.
OAuthStateMismatchException
¶
OAuthStateMismatchException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: UnauthorizedException
Raised when the callback's state does not match the cookie.
Either the login was not started by this browser — a forged callback — or the state cookie expired mid-consent. The client should restart the flow, not retry the callback.
OAuthCodeMissingException
¶
OAuthEmailMissingException
¶
OAuthEmailMissingException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: ValidationException
Raised when the provider returned no email address.
The user column is NOT NULL UNIQUE, so there is nothing to
store, and inventing an address would create an account nobody can
recover. The client's next step is to ask the provider for the email
scope, not to retry.
OAuthEmailTakenException
¶
OAuthEmailTakenException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: ConflictException
Raised when the email already belongs to another local account.
There is a next step for the user: sign in with the password they already have and link the provider from their account settings.
OAuthEmailUnverifiedException
¶
OAuthEmailUnverifiedException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: ConflictException
Raised when linking by email was allowed but the provider did not verify it.
Distinct from :class:OAuthEmailTakenException on purpose: this is
the barrier that stops someone who registered a provider identity
carrying the victim's address from taking the account over, and
there is no action the user can take that clears it. A client
that shows "sign in and link it" here is telling the person to do
something that cannot work.
OAuthRegistrationDisabledException
¶
OAuthRegistrationDisabledException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: ForbiddenException
Raised when the identity is new and account creation is off.
The deployment decided who may have an account
(AUTH_OAUTH_ALLOW_ACCOUNT_CREATION, inheriting
AUTH_SIGNUP_ENABLED), so this is a policy answer, not a
failure.
OAuthAccountInactiveException
¶
OAuthAccountInactiveException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: UnauthorizedException
Raised when the identity resolves to a deactivated account.
A deactivated account must not be revived by arriving through the provider instead of the login form.
OAuthAccountNotLinkedException
¶
OAuthAccountNotLinkedException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: NotFoundException
Raised when unlinking a provider the caller never linked.
The lookup is scoped to the caller, so a provider linked by somebody else answers exactly like one that was never linked — the endpoint is not an oracle for other people's accounts.
FileTooLargeException
¶
FileTooSmallException
¶
InvalidFileTypeException
¶
UploadTooLargeException
¶
UploadTooLargeException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: FileTooLargeException
Raised when read_upload_capped stops at its byte ceiling.
The request body is past the size the route accepts, so the answer is
413 Payload Too Large, the status an HTTP client and the OpenAI wire
expect for it. A subclass of :class:FileTooLargeException, so
except FileTooLargeException covers it too. details["max_bytes"]
carries the ceiling.
TusVersionException
¶
TusVersionException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when Tus-Resumable is missing or names another version.
tus 1.0.0 answers 412 Precondition Failed with the Tus-Version
header listing what the server speaks.
TusUploadNotFoundException
¶
TusUploadNotFoundException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when an upload does not exist or belongs to someone else.
Both cases answer the same 404: telling them apart would confirm to a
caller that an upload id it does not own is real.
TusUploadExpiredException
¶
TusUploadExpiredException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when an incomplete upload is past its Upload-Expires.
410 Gone, which the tus expiration extension allows next to 404.
The client restarts the upload from zero.
TusOffsetMismatchException
¶
TusOffsetMismatchException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when a PATCH writes at an offset the server does not hold.
409 Conflict, as the tus core protocol asks. details["offset"] is
the offset the server holds, so a client can continue from there without a
HEAD.
TusContentTypeException
¶
TusContentTypeException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when a PATCH is not application/offset+octet-stream.
415 Unsupported Media Type, as the tus core protocol asks.
TusInvalidHeaderException
¶
TusInvalidHeaderException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when a tus header is missing or malformed.
Covers Upload-Length (absent, not a non-negative integer),
Upload-Offset (same) and Upload-Metadata (a pair whose value is
not base64 of UTF-8 text). details["header"] names the header.
TusUploadTooLargeException
¶
TusUploadTooLargeException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when an upload or a chunk is bigger than allowed.
413: either Upload-Length is over the router's max_size (the
response then carries Tus-Max-Size), or a PATCH body would carry
the upload past its declared Upload-Length, or past the router's
max_chunk_size. details["max_bytes"] is the limit that was hit.
TusIdempotencyKeyReusedException
¶
TusIdempotencyKeyReusedException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when an Idempotency-Key is replayed for another upload.
The same caller sent the key before with a different Upload-Length:
replaying the first upload would hand back a URL for a file of the wrong
size, so the router answers 422 instead, as Stripe does for a reused
key.
TusBodyTimeoutException
¶
TusBodyTimeoutException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when a PATCH body stops arriving for longer than the read timeout.
408, which tempest-react-sdk's client retries (it re-reads the
offset with HEAD first). The chunk is discarded whole — the offset
stays where it was — and the upload's lock is released, so a half-open
mobile connection does not hold the upload until TCP gives up.
details["timeout_seconds"] is the limit.
TusChunkTooSmallException
¶
TusChunkTooSmallException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when a chunk other than the last is below the store's minimum.
:class:~tempest_fastapi_sdk.storage.tus.S3TusStore keeps one object per
chunk, so a client writing one byte per PATCH would create one object
per byte. details["min_bytes"] is the minimum.
TusQuotaExceededException
¶
TusQuotaExceededException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when a creation would pass the caller's active-upload quota.
details["limit"] names the limit hit ("uploads" or "bytes")
and details["max"] its value.
TusUploadCompletedException
¶
TusUploadCompletedException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when a PATCH targets an upload that already has every byte.
409, so tempest-react-sdk's client re-reads the offset with
HEAD, sees the upload complete and stops. Nothing is written and
on_complete does not run again. details["offset"] is the length.
TusUploadLockedException
¶
TusUploadLockedException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when another PATCH or DELETE of the upload is in progress.
409 without reading the body: the client re-reads the offset with
HEAD and retries after its backoff, and the server never spools two
bodies for one upload at once.
ImageDecodeException
¶
ImageDecodeException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when the bytes are not an image the declared format can decode.
Covers content no accepted decoder recognizes and a recognized image that is truncated or corrupt once its pixels are read.
ImageTypeMismatchException
¶
ImageTypeMismatchException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: InvalidFileTypeException
Raised when the image's real format differs from the declared one.
The declared type is client-controlled; the decoder reads the real format from the bytes, and the two must agree.
ImageFormatUnsupportedException
¶
ImageFormatUnsupportedException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: InvalidFileTypeException
Raised when the declared type is not one the function can re-encode.
Pillow ships no HEIC codec, so image/heic lands here, as does any
value that is not an image media type at all.
ImageTooLargeException
¶
ImageTooLargeException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: FileTooLargeException
Raised when the image has more pixels than the configured ceiling.
The check reads the dimensions from the header, before any pixel is decoded, so a small file that would expand to gigabytes of pixels (a decompression bomb) is refused without being expanded.
InsufficientBalanceException
¶
InsufficientBalanceException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when a debit asks for more than the wallet can give.
For a withdrawal "can give" means the available balance — the balance minus credits still on hold — not the whole balance.
ManualPayoutNotFoundException
¶
ManualPayoutNotFoundException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
ManualPayoutNotPendingException
¶
ManualPayoutNotPendingException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when a manual payout is no longer PENDING.
Another administrator (or a retry of the same request) already marked it paid or refused it, or the e-mail to the administrators failed and it was canceled. Nothing changed: the status, the wallet and the hooks were left as they were.
ManualPayoutReceiptMissingException
¶
ManualPayoutReceiptMissingException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
PayoutRejectedException
¶
PayoutRejectedException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when the payout provider definitively refused the transfer.
Definitive means the money did not leave: the provider answered with a
refusal, so the wallet debit can be returned safely.
:meth:~tempest_fastapi_sdk.wallet.WalletService.withdraw does that
before re-raising.
PayoutUncertainException
¶
PayoutUncertainException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when the payout outcome is unknown.
A timeout, a dropped connection or an answer that cannot be read: the
money may or may not have left. The wallet debit is kept — giving
it back would let the same balance be paid twice — and the case is
logged CRITICAL for reconciliation against the provider.
PixRefundExceedsBalanceException
¶
PixRefundExceedsBalanceException(
charge_id: str, *, requested_cents: int | None, refundable_cents: int
)
Bases: AppException
Raised when a refund asks for more than the charge has left.
"Left" is the charge's amount minus what
:meth:~tempest_fastapi_sdk.integrations.payment.PixRefundProvider.get_refunded_cents
counts, so a refund still in flight already reduces it. A full refund
(amount_cents=None) of a charge with nothing left raises this too:
there is nothing to give back, and answering with an empty refund would
look like one happened.
Attributes:
| Name | Type | Description |
|---|---|---|
charge_id |
str
|
The charge the refund was addressed to. |
requested_cents |
int | None
|
What was asked for; |
refundable_cents |
int
|
What the charge had left. |
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
charge_id
|
str
|
The charge the refund was addressed to. |
required |
requested_cents
|
int | None
|
What was asked for; |
required |
refundable_cents
|
int
|
What the charge had left. |
required |
PixRefundReferenceConflictException
¶
Bases: AppException
Raised when a refund reference is reused for a different refund.
The reference is the refund's idempotency key: the same reference with the same amount answers the refund that already exists, and the same reference with another amount is a second, different refund wearing the first one's key. Giving it back silently would let the caller believe the new amount went out.
Attributes:
| Name | Type | Description |
|---|---|---|
charge_id |
str
|
The charge the refund was addressed to. |
refund_reference |
str
|
The reused reference. |
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
charge_id
|
str
|
The charge the refund was addressed to. |
required |
refund_reference
|
str
|
The reused reference. |
required |
WrongExpectedVersionException
¶
WrongExpectedVersionException(
stream_id: str, *, expected_version: int | str, actual_version: int | None
)
Bases: ConflictException
Raised when an append's expected_version does not match the stream.
This is the optimistic-concurrency failure of an event store: someone
else appended to the stream between the read that produced
expected_version and this append. Both backends raise it — the SQL
store from its conditional UPDATE of the stream row, the KurrentDB
store by translating the client's WrongCurrentVersionError — so a
service handles one exception whatever the backend.
The usual reaction is to reload the aggregate and decide again; retrying the same append blindly would discard the other writer's decision.
Attributes:
| Name | Type | Description |
|---|---|---|
stream_id |
str
|
The stream the append targeted. |
expected_version |
int | str
|
What the caller expected — a version
number, or a :class: |
actual_version |
int | None
|
The stream's last version when the
append was refused, or |
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream_id
|
str
|
The stream the append targeted. |
required |
expected_version
|
int | str
|
The expected version or state. |
required |
actual_version
|
int | None
|
The stream's last version, or
|
required |
MessageCatalog
¶
Maps (locale, key) to message templates with locale fallback.
Locale keys are matched case-insensitively, first by the full tag
("pt-br") and then by the primary subtag ("pt"), so a catalog
holding "pt-BR" answers a request for "pt" and vice versa.
Initialize the catalog.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
translations
|
Mapping[str, Mapping[str, str]]
|
A mapping of
locale tag to |
required |
Notes
A primary-subtag index is built alongside the full-tag one, so a
request for "en" matches a catalog holding "en-US" and
vice versa. The first locale registered for a given primary
subtag wins.
locales
property
¶
Return the locale tags this catalog knows, lower-cased.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: The catalog's locale tags, lower-cased. |
supports
¶
Return whether this catalog can resolve keys for locale.
Matches full tags ("pt-BR") and primary subtags ("pt"),
case-insensitively and accepting _ as a separator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
locale
|
str
|
The locale tag to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|
bool
|
matching |
negotiate
¶
negotiate(accept_language: str | None, *, default_locale: str = DEFAULT_LOCALE) -> str
Pick the best available locale for an Accept-Language header.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
accept_language
|
str | None
|
The raw header value. |
required |
default_locale
|
str
|
Returned when no preferred locale matches the catalog. |
DEFAULT_LOCALE
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A locale tag the catalog can resolve, or |
str
|
|
resolve
¶
Resolve a message key in a locale, formatting with params.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The message key (an exception |
required |
locale
|
str
|
The locale tag to resolve in. |
required |
params
|
Mapping[str, Any] | None
|
Values interpolated into
the template via :meth: |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The formatted message, or |
str | None
|
is unknown in the resolved locale or its template names a |
str | None
|
param that |
str | None
|
The second |
str | None
|
to come back unformatted, and the literal braces reached the |
str | None
|
end user: pydantic's |
str | None
|
with |
str | None
|
( |
str | None
|
|
str | None
|
|
str | None
|
has a fallback for an unknown key. Use :meth: |
str | None
|
read the raw string. |
template
¶
Return the raw template of a key, without formatting it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The message key. |
required |
locale
|
str
|
The locale tag to read from. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The template as stored, placeholders included, or |
str | None
|
|
merge
¶
merge(other: Mapping[str, Mapping[str, str]]) -> MessageCatalog
Return a new catalog with other overlaid on this one.
Per-locale tables are merged key-by-key (other wins), so a
project can add new locales or override individual messages
without restating the built-in catalog.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Mapping[str, Mapping[str, str]]
|
Additional translations to overlay. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MessageCatalog |
MessageCatalog
|
A new, independent catalog. |
default_message_catalog
¶
default_message_catalog() -> MessageCatalog
Return a catalog with PT-BR + EN-US strings for the built-in codes.
Keys match the code attribute of every SDK exception
(NOT_FOUND, CONFLICT, UNAUTHORIZED, …). Extend it for
domain codes via :meth:MessageCatalog.merge.
Returns:
| Name | Type | Description |
|---|---|---|
MessageCatalog |
MessageCatalog
|
A fresh catalog instance (safe to mutate via |
MessageCatalog
|
meth: |
parse_accept_language
¶
Parse an Accept-Language header into locales by descending q.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
header
|
str | None
|
The raw header value (e.g.
|
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: Locale tags ordered from most to least preferred, |
list[str]
|
with the quality values stripped (e.g. |
list[str]
|
|
Notes
The header index is the sort tiebreaker, so tags sharing a quality value keep the order the client sent them in.
DEFAULT_LOCALE
module-attribute
¶
Locale used when Accept-Language is absent or matches nothing.
OAuthAudienceUnverifiableException
¶
OAuthAudienceUnverifiableException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: AppException
Raised when the registered client cannot check a token's audience.
Refusing is the only safe answer: without the audience check the
endpoint would accept a token minted for any other application (see
:class:OAuthTokenAudienceMismatchException), so a client that
cannot perform it disables the token-in-hand route rather than
weakening it.
It is a wiring fault, not a caller mistake — hence 501 and not 4xx.
Fix it by giving :class:~tempest_fastapi_sdk.OIDCProvider a
token_verifier or an RFC 7662 introspection_url, pointing a
client at a Google-shaped tokeninfo_url, or by overriding
verify_token_audience with whatever the provider does offer.
OAuthTokenAudienceMismatchException
¶
OAuthTokenAudienceMismatchException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: UnauthorizedException
Raised when the presented token was issued to a different app.
This is the attack the token-in-hand endpoint exists to survive. A
provider's userinfo endpoint answers whose token this is, never
who it was minted for — so any app that got the victim through a
consent screen holds a token that resolves to the victim's profile,
and posting it here would hand over the victim's session. Comparing
the token's audience against our own client_id is what closes
that: a token minted for somebody else's app is refused before any
account is touched.
Never raised by the redirect flow, whose token this service exchanged itself.
OAuthTokenRejectedException
¶
OAuthTokenRejectedException(
message: str | None = None,
*,
code: str | None = None,
status_code: int | None = None,
details: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
message_key: str | None = None,
message_params: dict[str, Any] | None = None,
field: str | None = None,
)
Bases: UnauthorizedException
Raised when the provider refuses the token the client presented.
Only the token-in-hand endpoint can hit this: the redirect flow never sees a token it did not mint itself. Expired, revoked, or simply invented — the provider is the authority and it said no, so the client's next step is to run the device flow again, not to retry with the same value.