diff --git a/vcert/common.py b/vcert/common.py index feabf23..feeb850 100644 --- a/vcert/common.py +++ b/vcert/common.py @@ -715,7 +715,10 @@ def process_server_response(r): log_errors(r.content) raise VenafiConnectionError(f"\n\tServer status: {r.status_code}" f"\n\tURL: {r.request.url}" - f"\n\tResponse: {r.content}") + f"\n\tResponse: {r.content}", + status_code = r.status_code, + url = r.request.url, + content = r.content) content_type = r.headers.get("content-type") # Content-type not present, return status and reason (if any) diff --git a/vcert/connection_tpp_abstract.py b/vcert/connection_tpp_abstract.py index 91ba5df..bb98732 100644 --- a/vcert/connection_tpp_abstract.py +++ b/vcert/connection_tpp_abstract.py @@ -28,7 +28,7 @@ from .common import CertField, CommonConnection, CertificateRequest, CSR_ORIGIN_LOCAL, CSR_ORIGIN_PROVIDED, \ CSR_ORIGIN_SERVICE, KeyType, CHAIN_OPTION_LAST, CHAIN_OPTION_FIRST, CHAIN_OPTION_IGNORE, Policy, ZoneConfig from .errors import VenafiError, ServerUnexptedBehavior, ClientBadData, RetrieveCertificateTimeoutError, \ - CertificateRequestError, CertificateRenewError + RetrieveCertificateNotFoundError, CertificateRequestError, CertificateRenewError from .http_status import HTTPStatus from .pem import parse_pem from .policy import RPA, SPA @@ -212,9 +212,13 @@ def retrieve_cert(self, cert_request): try: # TODO: Change _post() with post(args) status, data = self._post(URLS.CERTIFICATE_RETRIEVE, data=retrieve_request) - except VenafiError: - log.debug(f"Certificate with id {cert_request.id} not found") - status = 0 + except VenafiError as error: + log.debug(error.content) + status = error.status_code + if status == HTTPStatus.NOT_FOUND: + raise RetrieveCertificateNotFoundError(f"Certificate with id {cert_request.id} not found") + elif status == HTTPStatus.BAD_REQUEST: + raise ClientBadData(error.content) if status == HTTPStatus.OK: pem64 = data['CertificateData'] diff --git a/vcert/errors.py b/vcert/errors.py index 8adb4f1..505ad9a 100644 --- a/vcert/errors.py +++ b/vcert/errors.py @@ -16,7 +16,10 @@ class VenafiError(Exception): - pass + def __init__(self, *args, **kwargs): + super().__init__(*args) + for (k,v) in kwargs.items(): + setattr(self, k, v) class VenafiConnectionError(VenafiError): @@ -53,3 +56,7 @@ class VenafiParsingError(VenafiError): class RetrieveCertificateTimeoutError(VenafiError): pass + + +class RetrieveCertificateNotFoundError(VenafiError): + pass