diff --git a/src/main/java/it/gov/pagopa/print/payment/notice/functions/client/impl/PaymentNoticeGenerationRequestClientImpl.java b/src/main/java/it/gov/pagopa/print/payment/notice/functions/client/impl/PaymentNoticeGenerationRequestClientImpl.java index 8bae28b..e1f3485 100644 --- a/src/main/java/it/gov/pagopa/print/payment/notice/functions/client/impl/PaymentNoticeGenerationRequestClientImpl.java +++ b/src/main/java/it/gov/pagopa/print/payment/notice/functions/client/impl/PaymentNoticeGenerationRequestClientImpl.java @@ -34,8 +34,14 @@ private PaymentNoticeGenerationRequestClientImpl() { CodecRegistry pojoCodecRegistry = fromRegistries(getDefaultCodecRegistry(), fromProviders(pojoCodecProvider)); MongoClient mongoClient = MongoClients.create(connectionString); - MongoDatabase database = mongoClient.getDatabase(databaseName) - .withCodecRegistry(pojoCodecRegistry); + MongoDatabase database; + try { + database = mongoClient.getDatabase(databaseName) + .withCodecRegistry(pojoCodecRegistry); + } catch (Exception e) { + mongoClient.close(); + throw e; + } mongoCollection = database.getCollection(collectionName, PaymentNoticeGenerationRequest.class); } @@ -45,7 +51,7 @@ private PaymentNoticeGenerationRequestClientImpl() { } public static PaymentNoticeGenerationRequestClientImpl getInstance() { - if (instance == null) { + if(instance == null) { instance = new PaymentNoticeGenerationRequestClientImpl(); }