laceworksdk.exceptions
Package exceptions.
1# -*- coding: utf-8 -*- 2""" 3Package exceptions. 4""" 5 6import logging 7 8import requests 9 10logger = logging.getLogger(__name__) 11 12 13class LaceworkSDKException(Exception): 14 """ 15 Base class for all lacework package exceptions. 16 """ 17 pass 18 19 20class ApiError(LaceworkSDKException): 21 """ 22 Errors returned in response to requests sent to the Lacework APIs. 23 Several data attributes are available for inspection. 24 """ 25 26 def __init__(self, response): 27 assert isinstance(response, requests.Response) 28 29 # Extended exception attributes 30 self.response = response 31 """The :class:`requests.Response` object returned from the API call.""" 32 33 self.request = self.response.request 34 """The :class:`requests.PreparedRequest` of the API call.""" 35 36 self.status_code = self.response.status_code 37 """The HTTP status code from the API response.""" 38 39 self.status = self.response.reason 40 """The HTTP status from the API response.""" 41 42 self.details = None 43 """The parsed JSON details from the API response.""" 44 if "application/json" in \ 45 self.response.headers.get("Content-Type", "").lower(): 46 try: 47 self.details = self.response.json() 48 except ValueError: 49 logger.warning("Error parsing JSON response body") 50 51 if self.details: 52 if "data" in self.details.keys(): 53 self.message = self.details["data"].get("message") 54 elif "message" in self.details.keys(): 55 self.message = self.details["message"] 56 else: 57 self.message = None 58 """The error message from the parsed API response.""" 59 60 super().__init__( 61 "[{status_code}]{status} - {message}".format( 62 status_code=self.status_code, 63 status=" " + self.status if self.status else "", 64 message=self.message or "Unknown Error", 65 ) 66 ) 67 68 def __repr__(self): 69 return "<{exception_name} [{status_code}]>".format( 70 exception_name=self.__class__.__name__, 71 status_code=self.status_code, 72 ) 73 74 75class MalformedResponse(LaceworkSDKException): 76 """Raised when a malformed response is received from Lacework.""" 77 pass 78 79 80class RateLimitError(ApiError): 81 """LAcework Rate-Limit exceeded Error. 82 83 Raised when a rate-limit exceeded message is received and the request **will not** be retried. 84 """ 85 pass
class
LaceworkSDKException(builtins.Exception):
14class LaceworkSDKException(Exception): 15 """ 16 Base class for all lacework package exceptions. 17 """ 18 pass
Base class for all lacework package exceptions.
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- args
21class ApiError(LaceworkSDKException): 22 """ 23 Errors returned in response to requests sent to the Lacework APIs. 24 Several data attributes are available for inspection. 25 """ 26 27 def __init__(self, response): 28 assert isinstance(response, requests.Response) 29 30 # Extended exception attributes 31 self.response = response 32 """The :class:`requests.Response` object returned from the API call.""" 33 34 self.request = self.response.request 35 """The :class:`requests.PreparedRequest` of the API call.""" 36 37 self.status_code = self.response.status_code 38 """The HTTP status code from the API response.""" 39 40 self.status = self.response.reason 41 """The HTTP status from the API response.""" 42 43 self.details = None 44 """The parsed JSON details from the API response.""" 45 if "application/json" in \ 46 self.response.headers.get("Content-Type", "").lower(): 47 try: 48 self.details = self.response.json() 49 except ValueError: 50 logger.warning("Error parsing JSON response body") 51 52 if self.details: 53 if "data" in self.details.keys(): 54 self.message = self.details["data"].get("message") 55 elif "message" in self.details.keys(): 56 self.message = self.details["message"] 57 else: 58 self.message = None 59 """The error message from the parsed API response.""" 60 61 super().__init__( 62 "[{status_code}]{status} - {message}".format( 63 status_code=self.status_code, 64 status=" " + self.status if self.status else "", 65 message=self.message or "Unknown Error", 66 ) 67 ) 68 69 def __repr__(self): 70 return "<{exception_name} [{status_code}]>".format( 71 exception_name=self.__class__.__name__, 72 status_code=self.status_code, 73 )
Errors returned in response to requests sent to the Lacework APIs. Several data attributes are available for inspection.
ApiError(response)
27 def __init__(self, response): 28 assert isinstance(response, requests.Response) 29 30 # Extended exception attributes 31 self.response = response 32 """The :class:`requests.Response` object returned from the API call.""" 33 34 self.request = self.response.request 35 """The :class:`requests.PreparedRequest` of the API call.""" 36 37 self.status_code = self.response.status_code 38 """The HTTP status code from the API response.""" 39 40 self.status = self.response.reason 41 """The HTTP status from the API response.""" 42 43 self.details = None 44 """The parsed JSON details from the API response.""" 45 if "application/json" in \ 46 self.response.headers.get("Content-Type", "").lower(): 47 try: 48 self.details = self.response.json() 49 except ValueError: 50 logger.warning("Error parsing JSON response body") 51 52 if self.details: 53 if "data" in self.details.keys(): 54 self.message = self.details["data"].get("message") 55 elif "message" in self.details.keys(): 56 self.message = self.details["message"] 57 else: 58 self.message = None 59 """The error message from the parsed API response.""" 60 61 super().__init__( 62 "[{status_code}]{status} - {message}".format( 63 status_code=self.status_code, 64 status=" " + self.status if self.status else "", 65 message=self.message or "Unknown Error", 66 ) 67 )
Inherited Members
- builtins.BaseException
- with_traceback
- args
76class MalformedResponse(LaceworkSDKException): 77 """Raised when a malformed response is received from Lacework.""" 78 pass
Raised when a malformed response is received from Lacework.
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- args
81class RateLimitError(ApiError): 82 """LAcework Rate-Limit exceeded Error. 83 84 Raised when a rate-limit exceeded message is received and the request **will not** be retried. 85 """ 86 pass
LAcework Rate-Limit exceeded Error.
Raised when a rate-limit exceeded message is received and the request will not be retried.