U
    !h                     @   s  d dl mZmZmZ d dlmZ eG dd deZG dd deZG dd deZ	G d	d
 d
eZ
G dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZdS )     )absolute_importdivisionprint_function)python_2_unicode_compatiblec                       sb   e Zd Zd fdd	Zdd Zdd Zdd	 Zd
d Zdd Zdd Z	e
dd Zdd Z  ZS )TelnyxErrorNc                    s   || _ || _|| _|pi | _| jdd | _|  }|| _tt	| 
| |rt|drz|d}W n tk
r~   d}Y nX || _d S )Nz
request-iddecodezutf-8zE<Could not decode body as UTF-8. Please report to support@telnyx.com>)errorshttp_status	json_bodyhttp_headersget
request_idbuild_message_messagesuperr   __init__hasattrr   BaseException	http_body)selfr   r	   r   r
   r   message	__class__ O/home/ankuromar296_gmail_com/.local/lib/python3.8/site-packages/telnyx/error.pyr      s    
zTelnyxError.__init__c                 C   s   dj |  |  |  dS )Nz-{message}{other_errors_message}{full_details})r   other_errors_messagefull_details)formatextract_messager   r   r   r   r   r   r   $   s
    zTelnyxError.build_messagec                 C   s0   t | jtr(t| jdkr(dj| jdS dS d S )Nr   zFull details: {errors})r    )
isinstancer   listlenr   r   r   r   r   r   +   s    zTelnyxError.full_detailsc                 C   sJ   t | jtr2t| jdkr,| jd ddS dS n| jd kr@dS | jS d S )Nr   titler    )r!   r   r"   r#   r   r   r   r   r   r   1   s    
zTelnyxError.extract_messagec                 C   s0   |   }|dkrdj|dS |dkr(dS dS d S )N   zplus {count} other errors. )countzplus 1 other error. r    )errors_countr   )r   r&   r   r   r   r   <   s    z TelnyxError.other_errors_messagec                 C   s   t | jtrt| jS dS d S )N   )r!   r   r"   r#   r   r   r   r   r'   E   s    
zTelnyxError.errors_countc                 C   s*   | j pd}| jd k	r"d| j|S |S d S )Nz<empty message>zRequest {0}: {1})r   r   r   )r   msgr   r   r   __str__K   s    

zTelnyxError.__str__c                 C   s   | j S N)r   r   r   r   r   user_messageV   s    zTelnyxError.user_messagec                 C   s   d| j j| j| j| jf S )Nz-%s(message=%r, http_status=%r, request_id=%r))r   __name__r   r	   r   r   r   r   r   __repr__Z   s    zTelnyxError.__repr__)NNNNN)r-   
__module____qualname__r   r   r   r   r   r'   r*   propertyr,   r.   __classcell__r   r   r   r   r      s        	
r   c                       s   e Zd Zd fdd	Z  ZS )APIConnectionErrorNFc                    s"   t t| ||||| || _d S r+   )r   r3   r   should_retry)r   r   r   r	   r
   r   r4   r   r   r   r   d   s    	
    zAPIConnectionError.__init__)NNNNFr-   r/   r0   r   r2   r   r   r   r   r3   c   s        r3   c                   @   s   e Zd ZdS )InvalidRequestErrorNr-   r/   r0   r   r   r   r   r6   s   s   r6   c                   @   s   e Zd ZdS )AuthenticationErrorNr7   r   r   r   r   r8   x   s   r8   c                   @   s   e Zd ZdS )PermissionErrorNr7   r   r   r   r   r9   }   s   r9   c                   @   s   e Zd ZdS )ResourceNotFoundErrorNr7   r   r   r   r   r:      s   r:   c                   @   s   e Zd ZdS )MethodNotSupportedErrorNr7   r   r   r   r   r;      s   r;   c                   @   s   e Zd ZdS )TimeoutErrorNr7   r   r   r   r   r<      s   r<   c                   @   s   e Zd ZdS )UnsupportedMediaTypeErrorNr7   r   r   r   r   r=      s   r=   c                   @   s   e Zd ZdS )InvalidParametersErrorNr7   r   r   r   r   r>      s   r>   c                   @   s   e Zd ZdS )RateLimitErrorNr7   r   r   r   r   r?      s   r?   c                   @   s   e Zd ZdS )APIErrorNr7   r   r   r   r   r@      s   r@   c                   @   s   e Zd ZdS )ServiceUnavailableErrorNr7   r   r   r   r   rA      s   rA   c                       s   e Zd Zd fdd	Z  ZS )SignatureVerificationErrorNc                    s"   t t| || || _|| _d S r+   )r   rB   r   
sig_headertimestamp_header)r   r   rC   rD   r   r   r   r   r      s    z#SignatureVerificationError.__init__)Nr5   r   r   r   r   rB      s   rB   N)
__future__r   r   r   sixr   	Exceptionr   r3   r6   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   r   r   r   r   <module>   s    \