Esempio n. 1
0
    def __init__(
        self,
        received_data: Union[List, Dict],
        errors: Union[ListErrors, DictErrors] = None,
        message: str = "",
    ):
        """
        Represent a client data validation error.

        :param received_data: Data triggering the error. Should be a list or a dictionary in most cases.
        :param errors: To be used if a specific field triggered the error.
        If received_data is a list:
            key is supposed to be the index in received_data
            value is supposed to be a the same as if received_data was the dictionary at this index
        If received_data is a dict:
            key is supposed to be the field name in error
            value is supposed to be a list of error messages on this field
        :param message: The error message in case errors cannot be provided.
        """
        HTTPException.__init__(self, status_code=HTTPStatus.BAD_REQUEST.value)
        self.received_data = received_data
        self.errors = errors if errors else {"": [message]}
Esempio n. 2
0
 def __init__(self, detail: str = None):
     HTTPException.__init__(
         self,
         status_code=HTTPStatus.FORBIDDEN.value,
         detail=detail or HTTPStatus.FORBIDDEN.description,
     )
Esempio n. 3
0
 def __init__(self, detail: str = None):
     HTTPException.__init__(
         self,
         status_code=HTTPStatus.UNAUTHORIZED.value,
         detail=detail or HTTPStatus.UNAUTHORIZED.description,
     )