|
24 | 24 | import org.springframework.http.HttpEntity;
|
25 | 25 | import org.springframework.http.HttpHeaders;
|
26 | 26 | import org.springframework.http.HttpMethod;
|
| 27 | +import org.springframework.http.HttpStatus; |
27 | 28 | import org.springframework.http.MediaType;
|
28 | 29 | import org.springframework.http.ResponseEntity;
|
29 | 30 | import org.springframework.util.LinkedMultiValueMap;
|
@@ -130,13 +131,23 @@ public void send(MailgunEmail email) {
|
130 | 131 | String.class
|
131 | 132 | );
|
132 | 133 |
|
133 |
| - LOG.info("Mailgun response code: {}", response.getStatusCode()); |
134 |
| - LOG.debug("Mailgun response headers: {}", response.getHeaders()); |
135 |
| - LOG.info("Mailgun response body: {}", StringUtils.remove(response.getBody(), '\n')); |
| 134 | + boolean isWarning = response.getStatusCodeValue() == HttpStatus.OK.value(); |
| 135 | + String body = StringUtils.remove(response.getBody(), '\n'); |
| 136 | + logWarningOrDebug(isWarning, "Mailgun response code: {}", response.getStatusCode()); |
| 137 | + logWarningOrDebug(isWarning, "Mailgun response headers: {}", response.getHeaders()); |
| 138 | + logWarningOrDebug(isWarning, "Mailgun response body: {}", body); |
136 | 139 |
|
137 | 140 | } catch (UnsupportedEncodingException | RestClientException ex) {
|
138 | 141 | throw new EmailSendingException("Can't send mail to " + email.recipientAddress(), ex);
|
139 | 142 | }
|
140 | 143 | }
|
141 | 144 |
|
| 145 | + private static void logWarningOrDebug(boolean isWarning, String msg, Object... args) { |
| 146 | + if (isWarning) { |
| 147 | + LOG.warn(msg, args); |
| 148 | + } else { |
| 149 | + LOG.debug(msg, args); |
| 150 | + } |
| 151 | + } |
| 152 | + |
142 | 153 | }
|
0 commit comments