Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _handle_stream_errors(response):
if response.status_code >= 400:
raise GitLabAPIError(response.url, "Incorrect status code:", response.status_code)
def get_project_id(self, project_name):
encoded_project_name = urllib.parse.quote(project_name, safe=list())
url = "/projects/%s" % encoded_project_name
try:
res = self.make_request("GET", url)
return res["id"]
except GitLabAPIError as e:
if e.status_code == 404:
raise GitLabAPIError(url, 404, "Project not found: %s" % project_name) from None
else:
raise
def _handle_json_errors(response):
# Make sure we always have a dict containing some
# kind of error:
json_details = dict()
try:
json_details = response.json()
except ValueError:
json_details["error"] = ("Expecting json result, got %s" % response.text)
status_code = response.status_code
url = response.url
if 400 <= status_code < 500:
for key in ["error", "message"]:
if key in json_details:
raise GitLabAPIError(url, status_code, json_details[key])
raise GitLabAPIError(url, status_code, json_details)
if status_code >= 500:
raise GitLabAPIError(url, status_code, response.text)
# kind of error:
json_details = dict()
try:
json_details = response.json()
except ValueError:
json_details["error"] = ("Expecting json result, got %s" % response.text)
status_code = response.status_code
url = response.url
if 400 <= status_code < 500:
for key in ["error", "message"]:
if key in json_details:
raise GitLabAPIError(url, status_code, json_details[key])
raise GitLabAPIError(url, status_code, json_details)
if status_code >= 500:
raise GitLabAPIError(url, status_code, response.text)
def _handle_json_errors(response):
# Make sure we always have a dict containing some
# kind of error:
json_details = dict()
try:
json_details = response.json()
except ValueError:
json_details["error"] = ("Expecting json result, got %s" % response.text)
status_code = response.status_code
url = response.url
if 400 <= status_code < 500:
for key in ["error", "message"]:
if key in json_details:
raise GitLabAPIError(url, status_code, json_details[key])
raise GitLabAPIError(url, status_code, json_details)
if status_code >= 500:
raise GitLabAPIError(url, status_code, response.text)
def get_project_id(self, project_name):
encoded_project_name = urllib.parse.quote(project_name, safe=list())
url = "/projects/%s" % encoded_project_name
try:
res = self.make_request("GET", url)
return res["id"]
except GitLabAPIError as e:
if e.status_code == 404:
raise GitLabAPIError(url, 404, "Project not found: %s" % project_name) from None
else:
raise