def _validate(response):
    status_code_to_exc = {400: InvalidRequestError,
                          401: NotAuthorizedError,
                          402: MessageRejectedError,
                          403: NotAuthorizedError,
                          404: NotFoundError,
                          405: MethodNotSupportedError,
                          409: ConflictError,
                          429: SendingQuotaExceededError,
                          500: ServerError,
                          503: ServiceUnavailableError,
                          504: ServerTimeoutError}
    request = response.request
    url = request.url
    status_code = response.status_code
    data = request.body

    if DEBUG:
        print("{} {} ({}) => {}: {}".format(request.method, url, data,
                                            status_code, response.text))

    try:
        data = json.loads(data) if data else None
    except (ValueError, TypeError):
        pass

    if status_code == 200:
        return response
    elif status_code in status_code_to_exc:
        cls = status_code_to_exc[status_code]
        try:
            response = json.loads(response.text)
            kwargs = dict(url=url, status_code=status_code,
                          data=data)

            for key in ['message', 'server_error']:
                if response in key:
                    kwargs[key] = response[key]

            raise cls(**kwargs)

        except (ValueError, TypeError):
            raise cls(url=url, status_code=status_code,
                      data=data, message="Malformed")
    else:
        raise APIClientError(url=url, status_code=status_code,
                             data=data, message="Unknown status code.")
dataset/ETHPy150Open nylas/nylas-python/nylas/client/client.py/_validate/swapped operands of `in`