
    _jg                         S r SSKrSSKJrJrJr   " S S\5      r " S S\5      r " S S	\5      r	 " S
 S\5      r
 " S S\5      r " S S\5      r " S S\5      r " S S\5      rS\R                  S\SS4S jrg)z&
Error handling utilities for v2 API.
    N)DictAnyOptionalc                   `   ^  \ rS rSrSrSS\S\\   S\\R                     4U 4S jjjr
SrU =r$ )	FirecrawlError	   z(Base exception for Firecrawl API errors.messagestatus_coderesponsec                 <   > [         TU ]  U5        X l        X0l        g )N)super__init__r
   r   )selfr	   r
   r   	__class__s       U/home/rurouni/.local/lib/python3.13/site-packages/firecrawl/v2/utils/error_handler.pyr   FirecrawlError.__init__   s    !&     )r   r
   )NN)__name__
__module____qualname____firstlineno____doc__strr   intrequestsResponser   __static_attributes____classcell__)r   s   @r   r   r   	   s6    2! !(3- !RZ[c[l[lRm ! !r   r   c                       \ rS rSrSrSrg)BadRequestError   z)Raised when the request is invalid (400). Nr   r   r   r   r   r   r"   r   r   r    r       s    3r   r    c                       \ rS rSrSrSrg)UnauthorizedError   z.Raised when the request is unauthorized (401).r"   Nr#   r"   r   r   r%   r%      s    8r   r%   c                       \ rS rSrSrSrg)PaymentRequiredError   z&Raised when payment is required (402).r"   Nr#   r"   r   r   r(   r(      s    0r   r(   c                       \ rS rSrSrSrg)WebsiteNotSupportedError"   z+Raised when website is not supported (403).r"   Nr#   r"   r   r   r+   r+   "   s    5r   r+   c                       \ rS rSrSrSrg)RequestTimeoutError'   z$Raised when request times out (408).r"   Nr#   r"   r   r   r.   r.   '   s    .r   r.   c                       \ rS rSrSrSrg)RateLimitError,   z-Raised when the rate limit is exceeded (429).r"   Nr#   r"   r   r   r1   r1   ,   s    7r   r1   c                       \ rS rSrSrSrg)InternalServerError1   z3Raised when there's an internal server error (500).r"   Nr#   r"   r   r   r4   r4   1   s    =r   r4   r   actionreturnc                 T    U R                  5       nUR                  SS5      nUR                  SS5      nU R                  S:X  a!  SU SU SU 3n[        X`R                  U 5      eU R                  S:X  a!  SU SU SU 3n[        X`R                  U 5      eU R                  S:X  a!  SU SU SU 3n[        X`R                  U 5      eU R                  S:X  a!  SU SU SU 3n[        X`R                  U 5      eU R                  S:X  a!  SU SU SU 3n[        X`R                  U 5      eU R                  S:X  a!  SU SU SU 3n[        X`R                  U 5      eU R                  S:X  a!  SU SU SU 3n[        X`R                  U 5      eSU SU R                   SU SU 3n[        X`R                  U 5      e!    U R                  SS nUR                  5       (       a  SU 3nSU R                   3n GNS	U R                   3nS
n GN!   SU R                   3nS
n  GN= f= f)z
Handle API response errors and raise appropriate exceptions.

Args:
    response: The HTTP response object
    action: Description of the action being performed
    
Raises:
    FirecrawlError: Appropriate error based on status code
errorzNo error message provided.detailsz%No additional error details provided.Ni  z#Server returned non-JSON response: zFull response status: z+Server returned empty response with status zNo additional details availablez0Server returned unreadable response with status i  zBad Request: Failed to z. z - i  zUnauthorized: Failed to i  zPayment Required: Failed to i  z!Website Not Supported: Failed to i  zRequest Timeout: Failed to z as the request timed out. i  zRate Limit Exceeded: Failed to z!Internal Server Error: Failed to zUnexpected error during z: Status code )jsongettextstripr
   r    r%   r(   r+   r.   r1   r4   r   )r   r6   response_jsonerror_messageerror_detailsresponse_textr	   s          r   handle_response_errorrC   6   s   > %))'3OP%)))5\]  s"+F82m_CWg';';XFF				$,VHB}oSX)=)=xHH				$0=/]O\"7,@,@(KK				$5fXRcR_Q`a&w0D0DhOO				$/x7RS`Raaderdst!'+?+?JJ				$3F82m_CP]_W&:&:HEE				$5fXRcR_Q`a!'+?+?JJ,VHN8CWCWBXXZ[hZiilmzl{|W&:&:HEEM>
	>$MM$3/M""$$"Em_ U"89M9M8N O"MhNbNbMc d A	>NxOcOcNdeM=Ms)   4F; ;H'>8H9HH$ H'$H')r   r   typingr   r   r   	Exceptionr   r    r%   r(   r+   r.   r1   r4   r   r   rC   r"   r   r   <module>rF      s     & &!Y !	n 		 	
	> 	
	~ 	
	. 	
	^ 	
	. 	
5FH$5$5 5Fs 5Ft 5Fr   