U
    ô‰Vb¾  ã                   @   s€   d Z dZdZddlmZ ddlmZ ddlmZm	Z	 ddl
mZ ddlmZ G d	d
„ d
eƒZG dd„ deƒZG dd„ deƒZdS )zCopyright 2021, 3LizzGPL version 3zinfo@3liz.orgé    )Ú
QByteArray)ÚQDomDocument)ÚQgsServerExceptionÚQgsServerResponse)Úwrite_json_response)ÚLoggerc                       s:   e Zd Zd	eeeddœ‡ fdd„Zeddœdd„Z‡  ZS )
ÚServiceErroréô  N©ÚcodeÚmsgÚresponse_codeÚreturnc                    s>   t ƒ  |¡ d| _|| _|| _|| _t d | j||¡¡ d S )NÚLizmapz{} request error {}: {})	ÚsuperÚ__init__Úservicer   r   r   r   ÚcriticalÚformat©Úselfr   r   r   ©Ú	__class__© ú3/var/qgis-server/plugins/lizmap/server/exception.pyr      s    zServiceError.__init__)Úresponser   c                 C   s*   d| j | jdœ}| ¡  t||| jƒ dS )z Format error response
        Úfail)Ústatusr   ÚmessageN)r   r   Úclearr   r   )r   r   Úbodyr   r   r   ÚformatResponse   s    zServiceError.formatResponse)r	   )	Ú__name__Ú
__module__Ú__qualname__ÚstrÚintr   r   r!   Ú__classcell__r   r   r   r   r      s   r   c                       s*   e Zd Zdeeeddœ‡ fdd„Z‡  ZS )ÚExpressionServiceErrorr	   Nr
   c                    s   t ƒ  |||¡ d| _d S )NÚ
Expression)r   r   r   r   r   r   r   r   !   s    zExpressionServiceError.__init__)r	   )r"   r#   r$   r%   r&   r   r'   r   r   r   r   r(      s   r(   c                       s@   e Zd Zdeeeeeddœ‡ fdd„Zeefdœd	d
„Z‡  ZS )ÚLizmapFilterExceptionÚ r	   ú1.3.0N)r   r   Úlocatorr   Úversionr   c                    s4   t t| ƒ ||¡ || _|| _|| _|| _|| _d S )N)r   r   r   r   r   r-   r   r.   )r   r   r   r-   r   r.   r   r   r   r   (   s    zLizmapFilterException.__init__)r   c                 C   sˆ   t ƒ }| d¡}| d| j¡ | dd¡ | |¡ | d¡}| d| j¡ | | | j¡¡ | |¡ | jr|| d| j¡ | 	¡ dfS )	NZServiceExceptionReportr.   Úxmlnszhttp://www.opengis.net/ogcZServiceExceptionr   r-   ztext/xml; charset=utf-8)
r   ÚcreateElementÚsetAttributer.   ÚappendChildr   ÚcreateTextNoder   r-   ZtoByteArray)r   ÚdocÚrootÚelemr   r   r   r!   3   s    



z$LizmapFilterException.formatResponse)r+   r	   r,   )	r"   r#   r$   r%   r&   r   r   r!   r'   r   r   r   r   r*   &   s        ý    ýr*   N)Ú__copyright__Ú__license__Ú	__email__Úqgis.PyQt.QtCorer   Zqgis.PyQt.QtXmlr   Úqgis.serverr   r   Úlizmap.server.corer   Úlizmap.server.loggerr   Ú	Exceptionr   r(   r*   r   r   r   r   Ú<module>   s   