From c3a78045fb15a9f13c2f3842a5e86b781dada7fc Mon Sep 17 00:00:00 2001 From: Jacopo Date: Thu, 30 May 2024 12:37:49 +0200 Subject: [PATCH] catch --- .../PaymentNoticeGenerationRequestClientImpl.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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(); }