refactoring of the error handling

This commit is contained in:
Hossein Shafagh 2020-10-22 17:11:02 -07:00
parent 1c96ea9ab1
commit 2e7652962c
1 changed files with 7 additions and 5 deletions

View File

@ -221,7 +221,6 @@ def handle_cis_response(response):
:param response:
:return:
"""
return response.json()
if response.status_code == 404:
raise Exception("DigiCert: Order not in issued state.")
elif response.status_code == 406:
@ -229,6 +228,11 @@ def handle_cis_response(response):
elif response.status_code > 399:
raise Exception("DigiCert rejected request with the error:" + response.text)
if response.url.endswith("download"):
return response.content
else:
return response.json()
@retry(stop_max_attempt_number=10, wait_fixed=10000)
def get_certificate_id(session, base_url, order_id):
@ -247,11 +251,9 @@ def get_cis_certificate(session, base_url, order_id):
certificate_url = "{0}/platform/cis/certificate/{1}/download".format(base_url, order_id)
session.headers.update({"Accept": "application/x-pkcs7-certificates"})
response = session.get(certificate_url)
response_content = handle_cis_response(response)
if response.status_code == 404:
raise Exception("Order not in issued state.")
cert_chain_pem = convert_pkcs7_bytes_to_pem(response.content)
cert_chain_pem = convert_pkcs7_bytes_to_pem(response_content)
if len(cert_chain_pem) < 3:
raise Exception("Missing the certificate chain")
return cert_chain_pem