Ë
    8ø»j  ã                  ó2  — U d dl mZ d dlmZ d dlmZmZ d dlmZ erd dlm	Z	 d dl
mZ  ed«       G d„ d	e«      «       Z ed«       G d
„ de«      «       Z ed«       G d„ de«      «       Z ed«       G d„ de«      «       Z ed«       G d„ de«      «       Z ed«       G d„ de«      «       Z ed«       G d„ de«      «       Z ed«       G d„ de«      «       Z ed«       G d„ de«      «       Z ed«       G d„ de«      «       ZeeeeeedœZded<   g d¢Zy )!é    )Úannotations)Ú
HTTPStatus)ÚTYPE_CHECKINGÚAny)Ú
docs_group)ÚSelf)ÚHttpResponseÚErrorsc                  ó   — e Zd ZdZy)ÚApifyClientErrorz+Base class for all Apify API client errors.N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úJ/var/www/html/GAP/venv/lib/python3.12/site-packages/apify_client/errors.pyr   r      s   „ â5r   r   c                  óN   ‡ — e Zd ZdZddœdˆ fd„Zddœdˆ fd„Zed	d„«       Zˆ xZS )
ÚApifyApiErroruÌ  Error raised when the Apify API returns an error response.

    Instantiating `ApifyApiError` dispatches to the subclass matching the HTTP status code (e.g. 404 â†’ `NotFoundError`,
    any 5xx â†’ `ServerError`). Unmapped statuses stay on `ApifyApiError`. Existing `except ApifyApiError` handlers keep
    working because every subclass inherits from this class.

    The `type`, `message` and `data` fields from the response body are exposed for inspection but are treated as
    non-authoritative metadata â€” dispatch is driven by the status code only.

    Attributes:
        message: The error message from the API response.
        type: The error type identifier from the API response (e.g. `record-not-found`).
        status_code: The HTTP status code of the error response.
        attempt: The attempt number when the error was raised.
        http_method: The HTTP method of the failed request.
        data: Additional error data from the API response.
    ÚGET)Úmethodc               óÀ   •— t         ‰| �  | «      }| t        u rE|j                  }t        j                  |«      }|€|t        j                  k\  rt        }|�||_	        |S )zJDispatch to the subclass matching the response's HTTP status code, if any.)
ÚsuperÚ__new__r   Ústatus_codeÚ_STATUS_TO_CLASSÚgetr   ÚINTERNAL_SERVER_ERRORÚServerErrorÚ	__class__)ÚclsÚresponseÚattemptr   ÚinstanceÚstatusÚmappedr!   s          €r   r   zApifyApiError.__new__*   s^   ø€ ä‘7‘? 3Ó'ˆØ”-ÑØ×)Ñ)ˆFÜ%×)Ñ)¨&Ó1ˆFØˆ~ &¬J×,LÑ,LÒ"LÜ$�ØÐ!à%+�Ô"Øˆr   c               ó”  •— | j                  |«      }d|j                  › �| _        d| _        t	        t
        t
        f   «       | _        |�E|j                  d| j                  «      | _        |j                  d«      | _        d|v r
|d   | _        t        ‰| �%  | j                  «       |j                  | _
        || _        || _        y)a  Initialize the API error from a failed response.

        Args:
            response: The failed HTTP response from the Apify API.
            attempt: The attempt number when the request failed (1-indexed).
            method: The HTTP method of the failed request.
        zUnexpected error: NÚmessageÚtypeÚdata)Ú_extract_error_payloadÚtextr)   r*   ÚdictÚstrr+   r   r   Ú__init__r   r$   Úhttp_method)Úselfr#   r$   r   Úpayloadr!   s        €r   r0   zApifyApiError.__init__7   s­   ø€ ð ×-Ñ-¨hÓ7ˆà%7¸¿¹°Ð#GˆŒØ $ˆŒ	Üœœc˜‘NÓ$ˆŒ	àÐØ"Ÿ;™; y°$·,±,Ó?ˆDŒLØŸ™ FÓ+ˆDŒIØ˜Ñ Ø# F™O�”	ä‰Ñ˜Ÿ™Ô&à#×/Ñ/ˆÔØˆŒØ!ˆÕr   c                ó®   — 	 | j                  «       }t        |t        «      sy|j	                  d«      }t        |t        «      r|S dS # t        $ r Y yw xY w)zPReturn the `error` dict from the response body, or None if absent or unparsable.NÚerror)ÚjsonÚ
ValueErrorÚ
isinstancer.   r   )r#   r+   r5   s      r   r,   z$ApifyApiError._extract_error_payloadQ   sW   € ð	Ø—=‘=“?ˆDô ˜$¤Ô%ØØ—‘˜Ó!ˆÜ" 5¬$Ô/ˆuÐ9°TÐ9øô ò 	Ùð	ús   ‚A Á	AÁA)r#   r	   r$   Úintr   r/   Úreturnr   )r#   r	   r$   r9   r   r/   r:   ÚNone)r#   r	   r:   zdict[str, Any] | None)	r   r   r   r   r   r0   Ústaticmethodr,   Ú__classcell__©r!   s   @r   r   r      s4   ø„ ñð* MR÷ ð OT÷ "ð4 ò	:ó ô	:r   r   c                  ó   — e Zd ZdZy)ÚInvalidRequestErrorzCRaised when the Apify API returns an HTTP 400 Bad Request response.Nr   r   r   r   r@   r@   ^   s   „ âMr   r@   c                  ó   — e Zd ZdZy)ÚUnauthorizedErrorzDRaised when the Apify API returns an HTTP 401 Unauthorized response.Nr   r   r   r   rB   rB   c   s   „ âNr   rB   c                  ó   — e Zd ZdZy)ÚForbiddenErrorzARaised when the Apify API returns an HTTP 403 Forbidden response.Nr   r   r   r   rD   rD   h   ó   „ âKr   rD   c                  ó   — e Zd ZdZy)ÚNotFoundErrorzARaised when the Apify API returns an HTTP 404 Not Found response.Nr   r   r   r   rG   rG   m   rE   r   rG   c                  ó   — e Zd ZdZy)ÚConflictErrorz@Raised when the Apify API returns an HTTP 409 Conflict response.Nr   r   r   r   rI   rI   r   s   „ âJr   rI   c                  ó   — e Zd ZdZy)ÚRateLimitErrorzÐRaised when the Apify API returns an HTTP 429 Too Many Requests response.

    Rate-limited requests are retried automatically; this error is only raised after all retry attempts have been
    exhausted.
    Nr   r   r   r   rK   rK   w   s   „ òr   rK   c                  ó   — e Zd ZdZy)r    z²Raised when the Apify API returns an HTTP 5xx response.

    Server errors are retried automatically; this error is only raised after all retry attempts have been exhausted.
    Nr   r   r   r   r    r    €   s   „ òr   r    c                  ó$   ‡ — e Zd ZdZdˆ fd„Zˆ xZS )ÚInvalidResponseBodyErroraf  Error raised when a response body cannot be parsed.

    This occurs when the API returns a body that does not match its content type, for example a malformed JSON
    document. It is raised on a response the client already accepted, so it is not retried - a transfer that breaks
    mid-body surfaces as a transport error inside the retry loop instead.
    c                ó@   •— t         ‰| �  d«       d| _        || _        y)z‘Initialize the error from an unparsable response.

        Args:
            response: The HTTP response whose body could not be parsed.
        z!Response body could not be parsedzinvalid-response-bodyN)r   r0   Úcoder#   )r2   r#   r!   s     €r   r0   z!InvalidResponseBodyError.__init__‘   s!   ø€ ô 	‰ÑÐ<Ô=à+ˆŒ	Ø ˆ�r   )r#   r	   r:   r;   )r   r   r   r   r0   r=   r>   s   @r   rN   rN   ˆ   s   ø„ ñ÷	!ñ 	!r   rN   )i�  i‘  i“  i”  i™  i­  zdict[int, type[ApifyApiError]]r   )
r   r   rI   rD   r@   rN   rG   rK   r    rB   N)Ú
__future__r   Úhttpr   Útypingr   r   Úapify_client._docsr   r   Úapify_client.http_clientsr	   Ú	Exceptionr   r   r@   rB   rD   rG   rI   rK   r    rN   r   Ú__annotations__Ú__all__r   r   r   ú<module>rY      sš  ðÞ "å ß %å )áÝå6ñ ˆHÓô6�yó 6ó ð6ñ ˆHÓôG:Ð$ó G:ó ðG:ñT ˆHÓôN˜-ó Nó ðNñ ˆHÓôO˜ó Oó ðOñ ˆHÓôL�]ó Ló ðLñ ˆHÓôL�Mó Ló ðLñ ˆHÓôK�Mó Kó ðKñ ˆHÓô�]ó ó ðñ ˆHÓô�-ó ó ðñ ˆHÓô!Ð/ó !ó ð!ð* 
Ø	Ø	Ø	Ø	Ø	ñ4Ð Ð0ó ò�r   