[mail] add MailException to get better error messages

parent ea7821be
Pipeline #6913 failed with stages
in 16 minutes and 18 seconds
......@@ -17,6 +17,7 @@ module Gargantext.Core.Config.Mail (
, LoginType(..)
, SendEmailType(..)
, MailConfig(..)
, MailException(..)
-- * Utility functions
, gargMail
......@@ -32,6 +33,7 @@ module Gargantext.Core.Config.Mail (
)
where
import Control.Exception.Safe qualified as Exc
import Control.Monad.Fail (fail)
import Data.Maybe
import Data.Text (unpack)
......@@ -125,15 +127,24 @@ instance ToTable MailConfig where
-- }
newtype MailException =
MailException SomeException
deriving (Show)
instance Exception MailException
data GargMail = GargMail { gm_to :: Email
, gm_name :: Maybe Name
, gm_subject :: Text
, gm_body :: Text
}
-- | TODO add parameters to gargantext.ini
gargMail :: MailConfig -> GargMail -> IO ()
gargMail (MailConfig {..}) (GargMail { .. }) = do
gargMail mc gm = do
Exc.catch (gargMail' mc gm) $ \e -> Exc.throw (MailException e)
gargMail' :: MailConfig -> GargMail -> IO ()
gargMail' (MailConfig {..}) (GargMail { .. }) = do
let host = unpack _mc_mail_host
user = unpack _mc_mail_user
password = unpack _mc_mail_password
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment