Skip to content

Commit

Permalink
Merge pull request #231 from Clepsyd/feature/response-in-all-mailchim…
Browse files Browse the repository at this point in the history
…perror

Add response object in all MailChimpError exceptions
  • Loading branch information
charlesthk authored Jun 13, 2023
2 parents 29e16c9 + 60b108c commit f5cf415
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions mailchimp3/mailchimpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

_logger = logging.getLogger('mailchimp3.client')


def _enabled_or_noop(fn):
@functools.wraps(fn)
def wrapper(self, *args, **kwargs):
Expand All @@ -36,11 +37,19 @@ class MailChimpError(Exception):


def _raise_response_error(r):
# in case of a 500 error, the response might not be a JSON
"""
Return a MailChimpError to which we pass:
- the response object
- the response's JSON data if found.
"""
error_data = {"response": r}
try:
error_data = r.json()
json_data = r.json()
except ValueError:
error_data = { "response": r }
# in case of a 500 error, the response might not be a JSON
pass
else:
error_data.update(json_data)
raise MailChimpError(error_data)


Expand Down

0 comments on commit f5cf415

Please sign in to comment.