Closed silverbackdan closed 1 year ago
I don't recommend to use useFetch
for sending POST action but instead using $fetch
directly.
Cool, in that case it's probably prudent to update https://github.com/dword-design/nuxt-mail/blob/master/src/plugin-nuxt3.js
Something like this which could be typescript instead of js as well.
import SMTPTransport from "nodemailer/lib/smtp-transport";
import {$fetch, FetchError} from 'ofetch';
export default defineNuxtPlugin(() => {
const send = async (config: SMTPTransport) => {
try {
await $fetch("/mail/send", {
body: config,
method: "POST",
});
} catch (error) {
if (error instanceof FetchError) {
throw new Error(error.response?._data)
}
throw error
}
};
return {
provide: {
appMail: {
send
},
},
};
});
Thanks @dword-design
Sorry for another issue, but it looks to me as though useFetch simply returns a FetchError in a vue ref variable
error
so to return an error it shouldn't be trying to catch it.Something like this should work I believe