How to use the gitlabform.gitlab.core.UnexpectedResponseException function in gitlabform

To help you get started, we’ve selected a few gitlabform examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github egnyte / gitlabform / gitlabform / gitlab / core.py View on Github external
headers = {'PRIVATE-TOKEN': self.token}
        if data:
            response = self.session.request(method, url, headers=headers, data=data, timeout=10)
        elif json:
            response = self.session.request(method, url, headers=headers, json=json, timeout=10)
        else:
            response = self.session.request(method, url, headers=headers, timeout=10)
        logging.debug("response code=%s" % response.status_code)
        if response.status_code == 404:
            raise NotFoundException("Resource path='%s' not found!" % url)
        elif response.status_code == 204:
            # code calling this function assumes that it can do response.json() so fake it to return empty dict
            response.json = lambda: {}
            return response
        elif not self._is_expected_code(response.status_code, expected_codes):
            e = UnexpectedResponseException(
                "Request url='%s', method=%s, data='%s' failed "
                "- expected code(s) %s, got code %s & body: '%s'" %
                (url, method, data,
                 self._expected_code_to_str(expected_codes), response.status_code, response.content))
            e.status_code = response.status_code
            raise e
        else:
            return response