# -*- coding: utf-8 -*-

"""
cookiesapi

This file was automatically generated by APIMATIC v3.0 (
 https://www.apimatic.io ).
"""

from cookiesapi.api_helper import APIHelper
import cookiesapi.exceptions.api_exception
from cookiesapi.models.error_info import ErrorInfo


class FaultResponseException(cookiesapi.exceptions.api_exception.APIException):
    def __init__(self, reason, response):
        """Constructor for the FaultResponseException class

        Args:
            reason (string): The reason (or error message) for the Exception
                to be raised.
            response (HttpResponse): The HttpResponse of the API call.

        """
        super(FaultResponseException, self).__init__(reason, response)
        dictionary = APIHelper.json_deserialize(self.response.text)
        if isinstance(dictionary, dict):
            self.unbox(dictionary)

    def unbox(self, dictionary):
        """Populates the properties of this object by extracting them from a dictionary.

        Args:
            dictionary (dictionary): A dictionary representation of the object as
            obtained from the deserialization of the server's response. The keys
            MUST match property names in the API description.

        """
        self.fault = ErrorInfo.from_dictionary(dictionary.get('fault')) if dictionary.get('fault') else None
