dword-design / nuxt-mail

Adds email sending capability to a Nuxt.js app. Adds a server route, an injected variable, and uses nodemailer to send emails.
Other
247 stars 18 forks source link

Error handling??? #127

Closed raphaelbernhart closed 2 years ago

raphaelbernhart commented 2 years ago

Hi I really like the project but there is one problem. How to give the user feedback when the mail doesn't get sent.

I mean for some sites this is really a critical point of contact. When a potential client is reaching out to a company and the mail doesn't get sent but the client gets the feedback 'mail sent' the client maybe thinks that the company just isn't responding (for any reason).

But as a developer you aren't able to catch the error from this.$mail.send.

Is there something I don't see? Thanks :)

dword-design commented 2 years ago

The send function actually does error handling. If a request fails it will turn it into an Error and throw it. See https://github.com/dword-design/nuxt-mail/blob/master/src/plugin.js. Anything missing?

raphaelbernhart commented 2 years ago

Thanks for the answer :)

But when I try to catch the error with

try {
    this.$mail.send()
} catch(err) {
   console.log(err)
}

The error just gets logged to the console and I can't catch it in the try block.

I think axios catches it and throws the mail error. So you can't catch the error yourself in the highest scope (this.$mail.send()).

I'm currently not home but when I am I will send you a link to a example code. :)

dword-design commented 2 years ago

You have to add await to the function call, otherwise the error will be thrown outside the try-catch block 😃

raphaelbernhart commented 2 years ago

Yes, I cannot believe I missed that^^ Thanks for the help tho :)