Coder Social home page Coder Social logo

Comments (5)

germsvel avatar germsvel commented on June 18, 2024 2

Hi @Aduril and @jarvisjohnson, thanks so much for being quick to look through this. You're right that the main changes in Bamboo 2.0 are to the Bamboo.Mailer API. But in order for that change to work — for bamboo and bamboo_smtp users to be able to handle errors when emails fail to deliver — we also need to change what the adapter's deliver/2 function returns (See the changes to the adapter deliver callback):

-  @callback deliver(%Bamboo.Email{}, %{}) :: any
+  @type error :: Exception.t() | String.t()

+  @callback deliver(%Bamboo.Email{}, %{}) :: {:ok, any} | {:error, error}

That means adapters should no longer raise errors in the adapter code when failing to deliver emails. Instead they should return an {:error, error} tuple, so that Bamboo can handle that. Looking at the smtp_adapter.ex file, my guess is that these are the lines that should now return an error instead of raising one:

defp handle_response({:error, :no_credentials = reason}) do
raise SMTPError, {reason, "Username and password were not provided for authentication."}
end
defp handle_response({:error, reason, detail}) do
raise SMTPError, {reason, detail}
end
defp handle_response({:error, detail}) do
raise SMTPError, {:not_specified, detail}
end

If instead of raise SMTPError, bamboo_smtp returns {:error, %SMTPError{}}, then users who call Mailer.deliver_now will get that error tuple back. The users can then handle that in whatever way they see fit (e.g. retrying to send, or keeping a log of what failed, etc.)

For users who call Mailer.deliver_now!, Bamboo will raise the error the adapter passes back, so it'll do an raise %SMTPError{}.

As for the successful case, it seems that bamboo_smtp already returns an {:ok, response}, so that's perfect.

Does all that make sense?

from bamboo_smtp.

MatheusBueno782 avatar MatheusBueno782 commented on June 18, 2024 1

Since the pull request #177 that address to this issue was merged I am closing it.

thanks all for the contribution 🙂.

from bamboo_smtp.

Aduril avatar Aduril commented on June 18, 2024

As far as I see the the major change is towards the API of Bamboo.Mailer (please do not trust my word, check for yourself).

So the change should be an easy version upgrade, right?

from bamboo_smtp.

jarvisjohnson avatar jarvisjohnson commented on June 18, 2024

I think @Aduril is right, bumping the bamboo version seems to be all that is needed.

Have created a PR for this - #177

from bamboo_smtp.

jarvisjohnson avatar jarvisjohnson commented on June 18, 2024

Totally, thanks - I'll make some updates for it to return an :error tuple

from bamboo_smtp.

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.