I'm completely stumped on how to avoid this circular dependency. I have a TS module that sends emails, and one that handles errors. The error handler writes to a DB and sends emails. And the emailer needs to be able to handle errors. Then most apps use both of them.
For example, something like:
emailer.js
import err from "error-handler.js"
function sendEmail() {
try { trySendEmail() }
catch(e) { err(e) }
}
error-handler.js
import sendEmail from "emailer.js"
function err(e) {
sendEmail("Error Occurred", e)
}
Is there a right way to handle this situation? Thanks for your help!
internalemailersends emails and throws errors, moduleerrorhandlerimportsinternalemailerto send emails and ignores thrown exceptions, and moduleemailerthat sends emails withinternalemailerand handles thrown exceptions witherrorhandler.