diff --git a/backend-services/feed-service/app/utils/MongoConnection.scala b/backend-services/feed-service/app/utils/MongoConnection.scala index da1ac5b8d612c8cfaabdd0ac7aa17015d943cc4a..9b4366e1b6d20b2daf7fcde393e0e622d412b456 100644 --- a/backend-services/feed-service/app/utils/MongoConnection.scala +++ b/backend-services/feed-service/app/utils/MongoConnection.scala @@ -113,8 +113,16 @@ object MongoConnection { val futureResult: Future[UpdateResult] = collection.updateOne(filter, updates).toFuture() futureResult.map[Unit]((result: UpdateResult) => { + if (result.getMatchedCount == 0) { + throw new RuntimeException("No document with the given ID.") + } + if (!result.wasAcknowledged()) { - throw new RuntimeException("Update was not acknowledged") + throw new RuntimeException("Update was not acknowledged.") + } + + if (result.getModifiedCount() == 0) { + throw new RuntimeException("No document was modified.") } }) } @@ -132,11 +140,11 @@ object MongoConnection { futureResult.map[Unit]((result: DeleteResult) => { if (!result.wasAcknowledged()) { - throw new RuntimeException("Delete was not acknowledged") + throw new RuntimeException("Delete was not acknowledged.") } if (result.getDeletedCount() == 0) { - throw new RuntimeException("Delete was not acknowledged") + throw new RuntimeException("No document was deleted.") } }) }