Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if body:
body = json.dumps(body)
if params:
path += "?" + urllib.parse.urlencode(params)
self.__conn.request(method, path, body, headers=headers)
request = Request(method, path, body)
resp = Response(self.__conn.getresponse(), request)
if resp.status >= 400:
if resp.body:
resp_json = resp.body["error"]
resp_json["object"] = "error"
error = Resource.cast(resp_json, response=resp)
typ = error.type
name_parts = typ.split("_")
class_name = "".join(x.title() for x in name_parts)
# gets around inconsistencies in error naming
if not class_name.endswith("Error"):
class_name += "Error"
klass = locate("recurly.errors.%s" % class_name)
raise klass(
error.message + ". Recurly Request Id: " + resp.request_id,
error,
)
else:
raise ApiError(
"Unknown Error. Recurly Request Id: " + resp.request_id, None
)
if not class_name.endswith("Error"):
class_name += "Error"
klass = locate("recurly.errors.%s" % class_name)
raise klass(
error.message + ". Recurly Request Id: " + resp.request_id,
error,
)
else:
raise ApiError(
"Unknown Error. Recurly Request Id: " + resp.request_id, None
)
if resp.body:
return Resource.cast(resp.body, response=resp)
else:
return Resource.cast({}, Empty, resp)
except socket.error as e:
raise NetworkError(e)
class_name = "".join(x.title() for x in name_parts)
# gets around inconsistencies in error naming
if not class_name.endswith("Error"):
class_name += "Error"
klass = locate("recurly.errors.%s" % class_name)
raise klass(
error.message + ". Recurly Request Id: " + resp.request_id,
error,
)
else:
raise ApiError(
"Unknown Error. Recurly Request Id: " + resp.request_id, None
)
if resp.body:
return Resource.cast(resp.body, response=resp)
else:
return Resource.cast({}, Empty, resp)
except socket.error as e:
raise NetworkError(e)