Skip to content

Commit

Permalink
Merge pull request #2 from DHLWebAnalytics/feature/target
Browse files Browse the repository at this point in the history
Feature/target
  • Loading branch information
TillBuettnerDHL authored Oct 12, 2020
2 parents f718456 + d10a833 commit 8ffcc4d
Show file tree
Hide file tree
Showing 7 changed files with 1,883 additions and 1 deletion.
1 change: 1 addition & 0 deletions experiencecloudapis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

from .analytics_reports import Reports as AnalyticsReport
from .analytics import Analytics
from .target import Target
46 changes: 46 additions & 0 deletions experiencecloudapis/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from requests import Response


class ResponseError(Exception):
"""Raised for all non 200 response code from API methods"""
def __init__(self, response: Response) -> None:
self.response = response

@property
def headers(self):
headers_str = ''
if self.response.headers:
for header, value in self.response.headers.items():
headers_str += f'{header}: {value}\n'
return headers_str

def __str__(self):
response_str = """
Response Failed
==========================
Status Code:
{status_code}
==========================
Headers:
{headers}
==========================
Response:
{response_text}
==========================
"""
response_str = response_str.replace(' ', '')
response_str = response_str.replace('{status_code}',
str(self.response.status_code))
response_str = response_str.replace('{headers}', self.headers)
response_str = response_str.replace('{response_text}',
self.response.text)
return response_str


class PayloadTooLargeError(Exception):
"""Raised if POST Payload is above 60KB"""
def __init__(self, size):
self.size = size

def __str__(self):
return f'Maximal size for payload is 60KB. Input was: {self.size} KB'
Loading

0 comments on commit 8ffcc4d

Please sign in to comment.