Saltar a contenido

Excepciones

Jerarquía de errores de la librería. Todas las clases heredan de AlegraAPIError, por lo que except AlegraAPIError captura cualquier fallo de la API o del transporte. Ver también la guía de errores.

alegrapy.exceptions.AlegraAPIError

Bases: Exception

Exception raised for errors in the Alegra API response.

Attributes:

Name Type Description
message str

Explanation of the error.

status_code int

HTTP status code returned by the API.

response_body str

Raw response body text from the server.

retry_after float

Seconds to wait before retrying, taken from the Retry-After response header. None when the header is missing or cannot be parsed.

request_not_sent property

Whether the request provably never reached Alegra.

True only for a connect timeout or a refused/unresolvable connection. False when the request may have been processed, including every HTTP error response. Use it before re-creating non-idempotent records (invoices, payments).

alegrapy.exceptions.AlegraAuthError

Bases: AlegraAPIError

Authentication or authorization failed (HTTP 401 or 403).

alegrapy.exceptions.AlegraNotFoundError

Bases: AlegraAPIError

The requested resource does not exist (HTTP 404).

alegrapy.exceptions.AlegraValidationError

Bases: AlegraAPIError

The request payload was rejected by Alegra (HTTP 400 or 422).

alegrapy.exceptions.AlegraRateLimitError

Bases: AlegraAPIError

The account hit an API rate limit (HTTP 429).

Inspect retry_after for the server's suggested wait, when supplied.

alegrapy.exceptions.AlegraServerError

Bases: AlegraAPIError

Alegra failed while processing the request (any HTTP 5xx).

alegrapy.exceptions.AlegraConnectionError

Bases: AlegraAPIError

The connection failed or broke before a complete response was received.

This is ambiguous: the request MAY have reached Alegra and been processed, unless request_not_sent is True (connect timeout, connection refused or an unresolvable host). Do not re-create invoices or payments based on this class alone; check request_not_sent first.

alegrapy.exceptions.AlegraTimeoutError

Bases: AlegraAPIError

Alegra did not answer in time (read or other timeout).

The request may have reached the server and been processed, so non-idempotent requests (invoice or payment creation) must not be retried blindly.

alegrapy.exceptions.AlegraFileNotAvailableError

Bases: AlegraAPIError

The invoice has no downloadable file.

Alegra does not generate a PDF for draft invoices; the XML is only available once the invoice is stamped.

alegrapy.exceptions.AlegraStampError

Bases: AlegraAPIError

The credit note was created but its electronic stamping failed.

Alegra returns HTTP 400 with the created document; it is available as document so the caller can retry stamping instead of creating another note.

alegrapy.exceptions.AlegraAlreadyAnnulledError

Bases: AlegraAPIError

The invoice is already fully cancelled by an annulment note.

Attributes:

Name Type Description
invoice_id int or str

Invoice that is already annulled.

alegrapy.exceptions.AlegraUnverifiedCreateError

Bases: AlegraAPIError

A create failed ambiguously and Alegra could not confirm whether it happened.

The request may have created the record. Store the result of :meth:to_dict in a quarantine table/queue and reconcile it later; do not create the record again blindly.

Attributes:

Name Type Description
dedup_key str

Caller-supplied key used for the lookup.

client_id int or str

Client id used to scope the lookup.

resource str

Resource that was being created.

payload dict

Copy of the payload that was sent (marker included).

attempts int

Number of POSTs made.

status_code int

Status of the last error, if any.

response_body str

Body of the last error, if any.

to_dict()

Return a JSON-serializable summary suitable for a quarantine table.

Contains no credentials, headers or connection details.