@Override public void handle(HttpClientResponse httpClientResponse) { if (httpClientResponse.statusCode() == HttpStatus.SC_OK) { httpClientResponse.bodyHandler(buffer -> totalBuffer.appendBuffer(buffer)); httpClientResponse.endHandler( aVoid -> { try { MailgunSendResponse response = jsonMapper.readValue(totalBuffer.toString(), MailgunSendResponse.class); if (response == null || response.getId() == null || response.getId().isEmpty()) { failure(sendRequest, new Exception("Invalid Response to Send Request")); return; } EmailEntity emailEntity = sendRequest.getEmailEntity(); emailEntity.setMessageId(response.getId()); updateRecords(emailEntity); publishEvent(emailEntity, true); success(sendRequest, emailEntity); } catch (Throwable throwable) { updateRecords(sendRequest.getEmailEntity()); publishEvent(sendRequest.getEmailEntity(), false); failure(sendRequest, throwable); } }); } else { if (sendRequest.getAttempts() < ALLOWED_ATTEMPTS) { sendEmail(sendRequest); } else { updateRecords(sendRequest.getEmailEntity()); publishEvent(sendRequest.getEmailEntity(), false); failure( sendRequest, new Exception( "Failed to Send Email Using " + ALLOWED_ATTEMPTS + " Attempts with Response Code: " + httpClientResponse.statusCode())); } } }