jumpserver-python-sdk icon indicating copy to clipboard operation
jumpserver-python-sdk copied to clipboard

Passing code review

Open amingilani opened this issue 2 years ago • 0 comments

Hello,

I was just passing by and discovered these lines:

        except (requests.ConnectionError, requests.ConnectTimeout) as e:
            msg = "Connect endpoint {} error: {}".format(self.endpoint, e)
            logger.error(msg)
            raise RequestError(msg)

I just wanted to let you know that you can use from which allows exception chaining with a customer exception. Essentially allowing you to do this:


class HttpError(Exception):
    """Base class for all HTTP exceptions"""

class EndpointError(Exception):
    pass

        except (requests.ConnectionError, requests.ConnectTimeout) as e:
            raise EndpointError(f"Connect endpoint for {self.endpoint}") from e

And catch it from a higher layer.

amingilani avatar May 20 '22 02:05 amingilani