Git Product home page Git Product logo

Comments (7)

amro avatar amro commented on August 16, 2024

Hi Cameron, Sorry that the documentation isn't clear. I'll fix that soon. The paragraph you're referring to actually means the hash returned by the MailChimp API itself.

When you rescue the error, you can call error.message on it to get the message, which will be something like "MailChimp API Error: {submitted email} is already subscribed to {list}", as you mentioned. If you want the exact message returned by the API (i.e. without the prefix ("MailChimp API Error") that Gibbon inserts) then I'll need to change how Gibbon generates the error message slightly.

Let me know if this explanation helps. Thanks.

from gibbon.

NomNomCameron avatar NomNomCameron commented on August 16, 2024

I really like the way the mailchimp-api gem handles errors, it just gives the error (without "Mailchimp API Error:"). The reason I am using Gibbon instead of the mailchimp-api gem is because I couldn't get sending multiple parameters to list.subscribe to work (in my case ":double_optin => false" wasn't working with the mailchimp-api gem).

Pardon my ignorance but what do you call error.message on? What would I set a flash to to show the returned API error?

I really appreciate you getting back to me so quickly!

Thanks Amro!

from gibbon.

amro avatar amro commented on August 16, 2024

I understand. I'll make a change that doesn't contain the prefix soon. In the mean time, please just string replace it out (a bit of a hack, I know, but a short term solution). You can get MailChimp's error code (see their API docs) by calling .code on the instance of Gibbon::MailChimpError.

You call message on Gibbon:: MailChimpError, which extends Ruby's StandardError.

Something like this:

begin
  g.lists.subscribe(...)
rescue Gibbon::MailChimpError => e
  # do something with e.message here
end

from gibbon.

NomNomCameron avatar NomNomCameron commented on August 16, 2024

That will work beautifully until the "Mailchimp API Error" prefix is gone! Thank you so much!

If you wouldn't mind enlightening me on how this works I would GREATLY appreciate it:

What does Gibbon::MailChimpError => e do? The only thing I could think of is you have to put what MailChimpError returns into a variable in order to get the params out of the hash you want? So when I was doing Gibbon::MailChimpError.message Action Controller was interpreting that as me calling a "message" method on class "MailChimpError" and the reason that wasn't returning anything was because there is no MailChimpError class with a method of "message"?

from gibbon.

amro avatar amro commented on August 16, 2024

Gibbon subclasses Ruby's StandardError, which already has a message attribute, to add the code attribute. When the API returns an error Gibbon creates an instance of Its subclass (MailChimpError) and sets the error message returned by the API. That's what you're getting in the rescue block.

On Dec 21, 2013, at 7:13 PM, Cameron Craig [email protected] wrote:

That will work beautifully until the "Mailchimp API Error" prefix is gone! Thank you so much!

If you wouldn't mind enlightening me on how this works I would GREATLY appreciate it:

What does Gibbon::MailChimpError => e do? The only thing I could think of is you have to put what MailChimpError returns into a variable in order to get the params out of the hash you want? So when I was doing Gibbon::MailChimpError.message Action Controller was interpreting that as me calling a "message" method on class "MailChimpError"?


Reply to this email directly or view it on GitHub.

from gibbon.

NomNomCameron avatar NomNomCameron commented on August 16, 2024

Makes sense! I really appreciate all your help Amro! How long do you think it'll take to modify the error message that Gibbon generates?

from gibbon.

amro avatar amro commented on August 16, 2024

You're welcome. Modifying the error message alone will take seconds + the time to release. However, I recently accepted a pull request and I've not had time to fully test it functionally. I have to do that before I can release. I'll do this as soon as I can.

from gibbon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.