|
16 | 16 | import java.io.UnsupportedEncodingException; |
17 | 17 | import java.util.concurrent.atomic.AtomicInteger; |
18 | 18 |
|
| 19 | +import static java.lang.String.format; |
19 | 20 | import static org.simplejavamail.converter.EmailConverter.mimeMessageToEML; |
| 21 | +import static org.simplejavamail.mailer.internal.MailerException.*; |
20 | 22 |
|
21 | 23 | /** |
22 | 24 | * Separate closure that can be executed directly or from a thread. |
@@ -67,20 +69,19 @@ public void executeClosure() { |
67 | 69 | TransportRunner.sendMessage(operationalConfig.getClusterKey(), session, message, message.getAllRecipients()); |
68 | 70 | } |
69 | 71 | } catch (final UnsupportedEncodingException e) { |
70 | | - LOGGER.error("Failed to send email:\n{}", email.getId()); |
71 | | - LOGGER.trace("{}", email); |
72 | | - throw new MailerException(MailerException.INVALID_ENCODING, e); |
| 72 | + handleException(e, INVALID_ENCODING); |
73 | 73 | } catch (final MessagingException e) { |
74 | | - LOGGER.error("Failed to send email:\n{}", email.getId()); |
75 | | - LOGGER.trace("{}", email); |
76 | | - throw new MailerException(MailerException.GENERIC_ERROR, e); |
| 74 | + handleException(e, GENERIC_ERROR); |
77 | 75 | } catch (final Exception e) { |
78 | | - LOGGER.error("Failed to send email:\n{}", email.getId()); |
79 | | - LOGGER.trace("{}", email); |
80 | | - throw e; |
| 76 | + handleException(e, UNKNOWN_ERROR); |
81 | 77 | } |
82 | 78 | } |
83 | 79 |
|
| 80 | + private void handleException(final Exception e, String errorMsg) { |
| 81 | + LOGGER.trace("Failed to send email {}\n{}", email.getId(), email); |
| 82 | + throw new MailerException(format(errorMsg, email.getId()), e); |
| 83 | + } |
| 84 | + |
84 | 85 | private void logEmail(final MimeMessage message) { |
85 | 86 | if (transportModeLoggingOnly) { |
86 | 87 | if (LOGGER.isInfoEnabled()) { |
|
0 commit comments