From 460156d734e3d8298aef9fb694d0fd351f8557e4 Mon Sep 17 00:00:00 2001 From: Antonis Lempesis Date: Wed, 20 Oct 2021 22:49:56 +0000 Subject: [PATCH] catching email exceptions --- .../service/RepositoryServiceImpl.java | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java index 55847df..1162ecb 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java @@ -585,8 +585,12 @@ LOGGER.debug("json: " + jsonArray); , ResponseEntity.class); if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { - emailUtils.sendUserUpdateRepositoryInfoEmail(repository, authentication); - emailUtils.sendAdminUpdateRepositoryInfoEmail(repository, authentication); + try { + emailUtils.sendUserUpdateRepositoryInfoEmail(repository, authentication); + emailUtils.sendAdminUpdateRepositoryInfoEmail(repository, authentication); + } catch (Exception e) { + LOGGER.error("Error sending emails: " + e); + } } else LOGGER.debug(responseEntity.getBody().toString()); @@ -610,8 +614,12 @@ LOGGER.debug("json: " + jsonArray); ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class); if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { - emailUtils.sendUserRegistrationEmail(repository, authentication); - emailUtils.sendAdminRegistrationEmail(repository, authentication); + try { + emailUtils.sendUserRegistrationEmail(repository, authentication); + emailUtils.sendAdminRegistrationEmail(repository, authentication); + } catch (Exception e) { + LOGGER.error("Error sending emails: " + e); + } } else { LOGGER.debug(responseEntity.getBody().toString()); } @@ -646,8 +654,12 @@ LOGGER.debug("json: " + jsonArray); restTemplate.postForObject(uriComponents.toUri(), httpEntity, String.class); - emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); - emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); + try { + emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); + emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); + } catch (Exception e) { + LOGGER.error("Error sending emails: " + e); + } submitInterfaceValidation(e, registeredBy, repositoryInterface, false); @@ -665,8 +677,12 @@ LOGGER.debug("json: " + jsonArray); Repository repository = this.getRepositoryById(repoId); try { - emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); - emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); + try { + emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); + emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); + } catch (Exception e) { + LOGGER.error("Error sending emails: " + e); + } } catch (Exception e) { LOGGER.warn("Could not send emails", e); }