Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error handling #165

Open
AuHau opened this issue Apr 4, 2018 · 5 comments
Open

Better error handling #165

AuHau opened this issue Apr 4, 2018 · 5 comments

Comments

@AuHau
Copy link

AuHau commented Apr 4, 2018

Hey there,

first of all thanks for the library!

I would welcome to have better error handling as currently the Error reply is put as JSON into the Exception and not really parsed in anyway.
This makes hard to handle errors which might not really be errors in the application contexts (for example duplicated emails in a list).

I would suggest to extend the current MailChimpError class with status, title and details attribute. Maybe even subclass this class with frequently handled errors, for example like the duplicated emails usecase. Do you know about any other error which would be good to create a subclass for?

I could make PR for this if you would like me to. Please let me know if you would except it.

@stephenross
Copy link
Collaborator

Hi

We would be happy to see a PR for what you describe. The current wrapper leaves all error checking in the hands of the users, but if there are any standard errors that you want to provide specific notifications and messages for, we will be glad to take a look at the PR. If you are processing a specific error, please make sure you process that error on every endpoint that raises it.

@OleLaursen
Copy link
Contributor

The three classes of errors I've encountered so far is:

  1. Programming errors: bugs in the library or application code, but also a fair share of weird, undocumented limitations in Mailchimp (e.g. you can't have two merge fields with the same name only differing in uppercase/lowercase like "Somefield" and "someField")

  2. User input errors, e.g. incorrect email addresses

  3. Mailchimp service errors, typically coming from requests, e.g. "Connection refused", or "Connection closed" - typically these are transient and disappear after say an hour but I guess in some cases they could represent errors that require taking action, e.g. a problem with the local network

@lorie-castillano
Copy link

Hello everyone! Is there a way I can convert "Mailchimperror" to json format? so I can use it on my web microservice.

@stephenross
Copy link
Collaborator

MailChimpError is a custom python exception that we pass json data into, if you wrap your code in a try/except block catching the MailChimpError, you can pull that data out depending on your python version and serve the message information directly.

@rchavik
Copy link

rchavik commented Jul 19, 2018

Is this the correct way to access the exception data?

try:
    response = client.lists.webhooks.create(...)
except MailChimpError as ex:
    if 'errors' in ex.args[0]:
        raise UserError(ex.args[0]['errors'][0]['message']) #
    else:
        raise ex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants